how to set default company logo in odoo 12? - python

I 'am trying to set a default logo for the company, but nothing changes
I tried this code
class logocompany(models.Model):
_inherit = 'res.company'
#api.model
def _default_company_image(self):
image_path = modules.get_module_resource('auto_product', 'static/src/img', 'autoparts.png')
return tools.image_resize_image_big(base64.b64encode(open(image_path, 'rb').read()))
logo = fields.Binary(default=_default_company_image )
any help well be apprcited

Related

How do I get values from a one2many field?

I have three models which are connected with each other.
The first one is an inheriting of product.template (product_template.py) and as you see I have a one2many field which is connected to the second model showed in here.
When I want to access variables from product_template.py with dot notation I can see variable suggestion and I guess it works fine.
class ProductTemplate(models.Model):
_inherit = "product.template"
kestet_ids = fields.One2many('kestet.lines', 'product_template_id', string="Kestet", store=True)
class OnetoMany(models.Model):
_name = "kestet.lines"
partner_id = fields.Many2one("res.partner")
kestet = fields.Char(string="Emri i Kestit(n)")
vlera = fields.Integer(string="Vlera e Kestit(n)")
data = fields.Date()
sel1 = fields.Selection(
[('kontrate', 'Kontrate'), ('levrim', 'Levrim Kredie'), ('karabina', 'Karabina'), ('hipoteka', 'Hipoteka'),
('Celsat', 'Celsat'), ('Ne Perfundim', 'Ne Perfundim'),
('other', 'Tjeter')], string="Menyra Likujdimit")
pagesa1 = fields.Selection([('Cash', 'Cash'), ('Bank', 'Bank'), ('Klering', 'Klering')], string="Menyra Pageses")
product_template_id = fields.Many2one("product.template")
property_contract_id = fields.Many2one("property.contract")
Now when I try to access it from this other model property_contract.py and do the same thing as above, it doesn't give me variable suggestions and I can not access variable values.
class PropertyContract(models.Model):
_name = "property.contract"
_order = 'start_date'
name = fields.Char("Contract Number")
kestet2_ids = fields.Many2one('kestet.lines')
I also tried:
installment_id = fields.Many2one("product.templates")
installment_relation = fields.One2many(related="installment_id.kestet_ids")
It failed giving me results. I tried also the above code but didn't work...
What am I doing wrong here?

odoo14 on change only gets called on specific change

This is the on change function of one of my models in my odoo14 module:
#api.onchange('staende', 'name', 'length', 'height')
def change(self):
print("\033[92m +++ DEBUG#ONCHANGE +++")
print(self)
print("\033[93m", end="")
weirdly enough, the method only gets called when I change the name of the model but not when I change the length or height nor the staende attribute
this is what the model looks like:
class Halle(models.Model):
_name = 'rectanglemaps.halle'
_inherit = 'mail.thread'
_description = 'desc'
active = fields.Boolean('Active', default=True)
name = fields.Char(string="Name", required=True)
length = fields.Float(string="Länge", required=True)
height = fields.Float(string="Tiefe", required=True)
measurehalle = fields.Float(string="Rastermaß")
plan = fields.Image(string="Plan")
messe_id = fields.Many2one('rectanglemaps.messe', string="Messe")
staende = fields.One2many('rectanglemaps.stand', 'halle_id', string="Stände")
It appears, it was only a problem with hot module reloading. Restarting odoo with the flag -u MODULENAME solved the problem.

Odoo 12 how to display model records in one field, depending on the model chosen in other field

After several hours and differente approaches, can't reach to get what I need.
I'm developing a module to configure different kind of properties in a product.category, once a product is assigned a categ_id, I copy all the properties of this category to this product, for the user to assign the value of everyone.
Is pretty simple, model product.category.properties
class ProductCategoryProperties(models.Model):
_name = 'product.category.properties'
_order = "category_id, name"
#CONFIG. OPTIONS
VALUE_TYPES = [('char', 'Texto corto'), ('text', 'Texto largo'), ('num', 'Número'), ('oper', 'Operación'), ('list', 'Lista')]
OPERATION_TYPES = [('sum','Suma'),('sub','Resta'),('mul','Multiplicación'),('div','División')]
#FIELDS
category_id = fields.Many2one('product.category', string='Categoría', required=True, ondelete='cascade', index=True, copy=False)
name = fields.Char(string='Nombre', translate=True, required=True)
description = fields.Text(string='Descripción', translate=True)
value_type = fields.Selection(selection=VALUE_TYPES, default='char', string='Tipo valor', size=64, help='Tipo de valor de la propiedad', required=True)
value_min = fields.Float(string="Mínimo", help="Valor mínimo permitido")
value_max = fields.Float(string="Máximo", help="Valor máximo permitido")
operation_type = fields.Selection(selection=OPERATION_TYPES, default='sum', string='Tipo operación', size=64, help='Tipo de operación de la propiedad')
operation_field1 = fields.Many2one('product.category.properties', string='Campo 1', ondelete='cascade')
operation_field2 = fields.Many2one('product.category.properties', string='Campo 2', ondelete='cascade')
model_id = fields.Many2one('ir.model', string="Lista", ondelete='cascade')
Model product.properties (properties copied from product.category.properties when product.categ_id is filled.
class ProductProperties(models.Model):
_name = 'product.properties'
_order = "product_id, product_category_property_id"
#FIELDS
product_id = fields.Many2one('product.template', string='Producto', required=True, ondelete='cascade', index=True, copy=False)
product_category_property_id = fields.Many2one('product.category.properties', string='Propiedad', required=True, ondelete='cascade', index=True, copy=False)
value = fields.Char(string='Valor')
value_record = fields.Selection(string='Valor registro', selection='get_model_values', size=64)
value_wizard = fields.Integer(string='Valor wizard')
hide_record = fields.Boolean(string='Ocultar', compute='_hide_record', store=True)
#FUNCTIONS
def get_model_values(self):
#vals = [('1','Uno'), ('2','Dos')]
vals3 = []
res_partner = self.env['res.partner'].search([])
for i in res_partner: vals3.append([i.id, i.name])
uom_uom = self.env['uom.uom'].search([])
for j in uom_uom: vals3.append([j.id, j.name])
return vals3
As you can see that's easy, there are other functions to validate that values are between Min and Max values, and to calculate operations, for example Superficie (50) = Ancho (5) * Largo (10).
The problem comes when I need field "Valor" of "Lista" to display model records depending on the model chosen ("Lista".model_id), in this case Contacto (res.partner) but could be anyone.
I have tried with:
- different field types (value, value_record, value_wizard)
- tried some function like "def get_model_values", but needs to have the model hardcoded and doesn't really work to show different model records, for example res.partner for one record (Lista) and other model for other record (Lista2)
- heard about displaying a wizard to show records of a different model every time and return the id or other field of the selected record, but don't know how
- heard about using javascript/jquery to replace values directly on front, but don't know how
I have seen too that mail.message has a res_id integer field, that stores id of different record models. Model could be solved this way, but the problem is that I need to display record lists for the user to choose.
Anyone that could help would be appreciated.
Thanks!

How to correctly Update Odoo / Openerp website context?

I trying to adapt the module https://www.odoo.com/apps/modules/9.0/website_sale_product_brand/ to have a select box on the shop page, and filter by brand and category, and not to have to go to a diferent page and select the brand.
In that module they update context with the brand_id so the sale_product_domain function could append to the domain. In the module, it filter it as a charm, but in my code not....
Any guest?
When I debug self.env.context in the sale_product_domain function not brand if append, but in the website_sale_product_brand yes, with the exactly same code
controller.py
class WebsiteSale(website_sale):
#http.route(['/shop',
'/shop/page/<int:page>',
'/shop/category/<model("product.public.category"):category>',
'/shop/category/<model("product.public.category"):category>/page/<int:page>',
],type='http',auth='public',website=True)
def shop(self, page=0, category=None, search='', brand=None, **post):
# Update context to modify sale_product_domain function from website model
if brand:
context = dict(request.env.context)
context.setdefault('brand', int(brand))
request.env.context = context
result = super(WebsiteSale, self).shop(page=page, category=category,
brand=brand, search=search,
**post)
#append brand to keep so links mantain brand filter
keep = QueryURL('/shop',
brand=brand,
category=category and int(category),
search=search,)
#attrib=attrib_list TODO
#Update result
result.qcontext['keep'] = keep
result.qcontext['brands'] = http.request.env['product.brand'].search([]) #use to populate template select box
result.qcontext['sel_brand_id'] = brand #use to select the selected brand on brand select box
return result
models.py
class WebSite(models.Model):
_inherit = 'website'
#api.multi
def sale_product_domain(self):
domain = super(WebSite, self).sale_product_domain()
print self.env.context
if 'brand' in self.env.context:
domain.append(
('product_brand_id', '=', self.env.context['brand']))
return domain
ctx = dict (request.context)
ctx.update ({'bin_size': True})
request.context = ctx
That's it!

save ImageField mongoengine

I have following class definition in mongoengine orm:
import mongoengine as me
class Description(me.Document):
user = me.ReferenceField(User, required=True)
name = me.StringField(required=True, max_length=50)
caption = me.StringField(required=True, max_length=80)
description = me.StringField(required=True, max_length=100)
image = me.ImageField()
in my post method of my tornado web requesthandler:
from PIL import Image
def post(self, *args, **kwargs):
merchant = self._merchant
data = self._data
obj_data = {}
if merchant:
params = self.serialize() # I am getting params dict. NO Issues with this.
obj_data['name'] = params.get('title', None)
obj_data['description'] = params.get('description', None)
path = params.get('file_path', None)
image = Image.open(path)
print image # **
obj_data['image'] = image # this is also working fine.
obj_data['caption'] = params.get('caption', None)
obj_data['user'] = user
des = Description(**obj_data)
des.save()
print obj_data['image'] # **
print des.image # This is printing as <ImageGridFsProxy: None>
** print obj_data['image'] and print image are printing following:
<PIL.PngImagePlugin.PngImageFile image mode=1 size=290x290 at 0x7F83AE0E91B8>
but
des.image still remains None.
Please suggest me what is wrong here.
Thanks in advance to all.
You can not just put PIL objects into a field with obj.image = image that way. You must do:
des = Description()
des.image.put(open(params.get('file_path', None)))
des.save()
In other words, ImageField should be filled with file object after creating an instance by calling put method.

Categories