I created two custom fields in 'sale.order.line' which work just fine:
class rlmSalesOrder(models.Model):
_inherit = 'sale.order.line'
fromeachof = fields.Integer(string='From Each Of',store=True,default="1")
total_ordered = fields.Integer(string='Total Ordered',compute='_compute_total_ordered')
I also created two custom fields in 'sale.order' which also work just fine:
class rlmSaleOrder(models.Model):
_inherit = 'sale.order'
project_name = fields.Char(string='Project Name',store=True)
due_date = fields.Date(string='Due Date',store=True)
Now when the order is converted to an invoice, and I want to show the value of "fromeachof", I created the field under "account.invoice.line" and related it to "sale_line_ids.fromeachof" which also works fine:
class rlmInvoice(models.Model):
_inherit = 'account.invoice.line'
fromeachof = fields.Integer(string='From Each Of',store=True, related="sale_line_ids.fromeachof")
However, I can't create "project_name" or "due_date" under "account.invoice" to show on the invoice:
class rlmAccountInvoice(models.Model):
_inherit = "account.invoice"
project_name = fields.Char(string='Project Name',store=True,related="sale_order_id.project_name")
due_date = fields.Date(string='Due Date',store=True,related="sale_order_id.project_name")
No matter what I put in the related field, I get a Key Error (I've tried every combination I could think of):
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/werkzeug/serving.py", line 209, in run_wsgi
execute(self.server.app)
File "/usr/local/lib/python3.5/dist-packages/werkzeug/serving.py", line 197, in execute
application_iter = app(environ, start_response)
File "/opt/odoo/odoo/service/server.py", line 250, in app
return self.app(e, s)
File "/opt/odoo/odoo/service/wsgi_server.py", line 166, in application
return application_unproxied(environ, start_response)
File "/opt/odoo/odoo/service/wsgi_server.py", line 154, in application_unproxied
result = handler(environ, start_response)
File "/opt/odoo/odoo/http.py", line 1318, in __call__
return self.dispatch(environ, start_response)
File "/opt/odoo/odoo/http.py", line 1292, in __call__
return self.app(environ, start_wrapped)
File "/usr/local/lib/python3.5/dist-packages/werkzeug/wsgi.py", line 600, in __call__
return self.app(environ, start_response)
File "/opt/odoo/odoo/http.py", line 1473, in dispatch
odoo.registry(db).check_signaling()
File "/opt/odoo/odoo/__init__.py", line 76, in registry
return modules.registry.Registry(database_name)
File "/opt/odoo/odoo/modules/registry.py", line 61, in __new__
return cls.new(db_name)
File "/opt/odoo/odoo/modules/registry.py", line 85, in new
odoo.modules.load_modules(registry._db, force_demo, status, update_module)
File "/opt/odoo/odoo/modules/loading.py", line 383, in load_modules
registry.setup_models(cr)
File "/opt/odoo/odoo/modules/registry.py", line 277, in setup_models
model._setup_fields()
File "/opt/odoo/odoo/models.py", line 2425, in _setup_fields
field.setup_full(self)
File "/opt/odoo/odoo/fields.py", line 471, in setup_full
self._setup_related_full(model)
File "/opt/odoo/odoo/fields.py", line 508, in _setup_related_full
field = target._fields[name]
KeyError: 'sale_order_id'
I can't figure out how to link the fields. What's the right way to do this?