Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

1

How to override Your company data through a custom module in v8 ?

By
PY
on 7/1/15, 9:39 AM 728 views

Hi !

In v7, you could do:

<record id="base.main_company" model="res.company"> <field name="name">Your New Company</field> <field name="partner_id" ref="main_partner"/> <field name="rml_header1">Your New Company Tagline</field> <field name="currency_id" ref="base.EUR"/> </record>

But in v8 you can't. Any other way doing this ?

2
PY
On 7/1/15, 10:18 AM

Update: (better alternative)

xml

<data noupdate="1">
<function model="res.company" name="set_my_company_data"/>
</data>

python

class ResCompany(models.Model):
_inherit = "res.company"

@api.model
def set_my_company_data(self):
_logger.info("Setting company data...")
module_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
img_path = os.path.join(module_dir, 'static/img/custom_company_logo.png')
with open(img_path) as img:
logo = img.read().encode('base64')

self.browse(1).write({
'name': "My Custom Name",
'logo': logo,
[...]
})
_logger.info("... done.")

_____________________________

I found a workaround:


        <record id="foo" model="res.company">
<field name="inherit_id" ref="base.main_company"/>
<field name="name">Foo</field>
<field name="logo" type="base64" file="foo/static/img/foo_logo.png"/>
           <field name="street">5 rue Foo Bar</field>
</record>

The .py that allows that to work:

class ResCompany(models.Model):
_inherit = "res.company"

@api.model
def create(self, vals):
inherit_id = vals.get('inherit_id', False)
if inherit_id:
# this is an inheritance
del vals['inherit_id']
super(ResCompany, self.browse(inherit_id)).write(vals)
return self
return super(ResCompany, self).create(vals)
0
Artem
On 9/22/16, 1:49 PM

The query update ir_model_data set noupdate=False where noupdate=True must make everything updatable.

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 7/1/15, 9:39 AM
Seen: 728 times
Last updated: 9/22/16, 1:49 PM