Make partner_default_properties multi-company proof by storing defaults on res.company
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from . import res_company
|
||||
from . import res_config_settings
|
||||
from . import res_partner
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class ResCompany(models.Model):
|
||||
_inherit = 'res.company'
|
||||
|
||||
customer_fiscal_position_id = fields.Many2one(
|
||||
comodel_name='account.fiscal.position',
|
||||
string='Default Customer Fiscal Position',
|
||||
)
|
||||
customer_payment_term_id = fields.Many2one(
|
||||
comodel_name='account.payment.term',
|
||||
string='Default Customer Payment Terms',
|
||||
)
|
||||
@@ -1,9 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from odoo import fields, models
|
||||
|
||||
PARAM_FISCAL_POSITION = 'partner_default_properties.fiscal_position_id'
|
||||
PARAM_PAYMENT_TERM = 'partner_default_properties.payment_term_id'
|
||||
|
||||
|
||||
class ResConfigSettings(models.TransientModel):
|
||||
_inherit = 'res.config.settings'
|
||||
@@ -11,25 +8,12 @@ class ResConfigSettings(models.TransientModel):
|
||||
customer_fiscal_position_id = fields.Many2one(
|
||||
comodel_name='account.fiscal.position',
|
||||
string='Default Fiscal Position',
|
||||
related='company_id.customer_fiscal_position_id',
|
||||
readonly=False,
|
||||
)
|
||||
customer_payment_term_id = fields.Many2one(
|
||||
comodel_name='account.payment.term',
|
||||
string='Default Payment Terms',
|
||||
related='company_id.customer_payment_term_id',
|
||||
readonly=False,
|
||||
)
|
||||
|
||||
def get_values(self):
|
||||
res = super().get_values()
|
||||
ICP = self.env['ir.config_parameter'].sudo()
|
||||
fp_id = ICP.get_param(PARAM_FISCAL_POSITION)
|
||||
pt_id = ICP.get_param(PARAM_PAYMENT_TERM)
|
||||
res.update({
|
||||
'customer_fiscal_position_id': int(fp_id) if fp_id else False,
|
||||
'customer_payment_term_id': int(pt_id) if pt_id else False,
|
||||
})
|
||||
return res
|
||||
|
||||
def set_values(self):
|
||||
super().set_values()
|
||||
ICP = self.env['ir.config_parameter'].sudo()
|
||||
ICP.set_param(PARAM_FISCAL_POSITION, self.customer_fiscal_position_id.id or False)
|
||||
ICP.set_param(PARAM_PAYMENT_TERM, self.customer_payment_term_id.id or False)
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from odoo import models
|
||||
from .res_config_settings import PARAM_FISCAL_POSITION, PARAM_PAYMENT_TERM
|
||||
|
||||
|
||||
class ResPartner(models.Model):
|
||||
@@ -8,14 +7,12 @@ class ResPartner(models.Model):
|
||||
|
||||
def default_get(self, fields_list):
|
||||
res = super().default_get(fields_list)
|
||||
ICP = self.env['ir.config_parameter'].sudo()
|
||||
company = self.env.company
|
||||
|
||||
fp_id = ICP.get_param(PARAM_FISCAL_POSITION)
|
||||
if fp_id:
|
||||
res['property_account_position_id'] = int(fp_id)
|
||||
if company.customer_fiscal_position_id:
|
||||
res['property_account_position_id'] = company.customer_fiscal_position_id.id
|
||||
|
||||
pt_id = ICP.get_param(PARAM_PAYMENT_TERM)
|
||||
if pt_id:
|
||||
res['property_payment_term_id'] = int(pt_id)
|
||||
if company.customer_payment_term_id:
|
||||
res['property_payment_term_id'] = company.customer_payment_term_id.id
|
||||
|
||||
return res
|
||||
|
||||
Reference in New Issue
Block a user