[FIX] sale_management: do not recompute quote template on company change
closes odoo/odoo#108380 X-original-commit: f143893af2d1bd2c167c1aa2e23e0bedc1a46c7a Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com>
This commit is contained in:
@@ -4,8 +4,14 @@
|
||||
from . import models
|
||||
from . import controllers
|
||||
from odoo.api import Environment, SUPERUSER_ID
|
||||
from odoo.tools import column_exists, create_column
|
||||
|
||||
|
||||
def pre_init_hook(cr):
|
||||
"""Do not compute the sale_order_template_id field on existing SOs."""
|
||||
if not column_exists(cr, "sale_order", "sale_order_template_id"):
|
||||
create_column(cr, "sale_order", "sale_order_template_id", "int4")
|
||||
|
||||
def uninstall_hook(cr, registry):
|
||||
env = Environment(cr, SUPERUSER_ID, {})
|
||||
res_ids = env['ir.model.data'].search([
|
||||
|
||||
@@ -58,13 +58,14 @@ The Dashboard for the Sales Manager will include
|
||||
'demo': [
|
||||
'data/sale_order_template_demo.xml',
|
||||
],
|
||||
'application': True,
|
||||
'uninstall_hook': 'uninstall_hook',
|
||||
'post_init_hook': 'post_init_hook',
|
||||
'assets': {
|
||||
'web.assets_frontend': [
|
||||
'sale_management/static/src/js/**/*',
|
||||
],
|
||||
},
|
||||
'application': True,
|
||||
'pre_init_hook': 'pre_init_hook',
|
||||
'post_init_hook': 'post_init_hook',
|
||||
'uninstall_hook': 'uninstall_hook',
|
||||
'license': 'LGPL-3',
|
||||
}
|
||||
|
||||
@@ -28,16 +28,10 @@ class SaleOrder(models.Model):
|
||||
|
||||
#=== COMPUTE METHODS ===#
|
||||
|
||||
@api.depends('company_id')
|
||||
# Do not make it depend on `company_id` field
|
||||
# It is triggered manually by the _onchange_company_id below iff the SO has not been saved.
|
||||
def _compute_sale_order_template_id(self):
|
||||
for order in self:
|
||||
if order._origin.id: # If record has already been saved
|
||||
# 1) Do NOT update existing SO's template and dependent fields
|
||||
# Especially when installing sale_management in a db
|
||||
# already containing SO records
|
||||
# 2) Only apply the company default if the company is modified before the record is saved
|
||||
# to make sure the lines are not magically reset when the company is modified (internal odoo issue)
|
||||
continue
|
||||
company_template = order.company_id.sale_order_template_id
|
||||
if company_template and order.sale_order_template_id != company_template:
|
||||
order.sale_order_template_id = order.company_id.sale_order_template_id.id
|
||||
@@ -86,6 +80,13 @@ class SaleOrder(models.Model):
|
||||
|
||||
#=== ONCHANGE METHODS ===#
|
||||
|
||||
@api.onchange('company_id')
|
||||
def _onchange_company_id(self):
|
||||
"""Trigger quotation template recomputation on unsaved records company change"""
|
||||
if self._origin.id:
|
||||
return
|
||||
self._compute_sale_order_template_id()
|
||||
|
||||
@api.onchange('sale_order_template_id')
|
||||
def _onchange_sale_order_template_id(self):
|
||||
sale_order_template = self.sale_order_template_id.with_context(lang=self.partner_id.lang)
|
||||
|
||||
Reference in New Issue
Block a user