Add partner_default_properties addon with default fiscal position and payment terms for new customers
This commit is contained in:
@@ -0,0 +1,2 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from . import models
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
{
|
||||||
|
'name': 'Partner Default Properties',
|
||||||
|
'version': '16.0.1.0.0',
|
||||||
|
'summary': 'Set company-wide defaults for fiscal position and payment terms on new customers',
|
||||||
|
'category': 'Accounting',
|
||||||
|
'author': 'Van Bernaert',
|
||||||
|
'depends': ['base', 'account', 'sale'],
|
||||||
|
'data': [
|
||||||
|
'views/res_config_settings_views.xml',
|
||||||
|
],
|
||||||
|
'installable': True,
|
||||||
|
'auto_install': False,
|
||||||
|
'license': 'LGPL-3',
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from . import res_config_settings
|
||||||
|
from . import res_partner
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
# -*- 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'
|
||||||
|
|
||||||
|
customer_fiscal_position_id = fields.Many2one(
|
||||||
|
comodel_name='account.fiscal.position',
|
||||||
|
string='Default Fiscal Position',
|
||||||
|
compute='_compute_customer_fiscal_position_id',
|
||||||
|
inverse='_set_customer_fiscal_position_id',
|
||||||
|
)
|
||||||
|
customer_payment_term_id = fields.Many2one(
|
||||||
|
comodel_name='account.payment.term',
|
||||||
|
string='Default Payment Terms',
|
||||||
|
compute='_compute_customer_payment_term_id',
|
||||||
|
inverse='_set_customer_payment_term_id',
|
||||||
|
)
|
||||||
|
|
||||||
|
def _compute_customer_fiscal_position_id(self):
|
||||||
|
ICP = self.env['ir.config_parameter'].sudo()
|
||||||
|
param = ICP.get_param(PARAM_FISCAL_POSITION)
|
||||||
|
for rec in self:
|
||||||
|
rec.customer_fiscal_position_id = int(param) if param else False
|
||||||
|
|
||||||
|
def _set_customer_fiscal_position_id(self):
|
||||||
|
ICP = self.env['ir.config_parameter'].sudo()
|
||||||
|
for rec in self:
|
||||||
|
ICP.set_param(PARAM_FISCAL_POSITION, rec.customer_fiscal_position_id.id or False)
|
||||||
|
|
||||||
|
def _compute_customer_payment_term_id(self):
|
||||||
|
ICP = self.env['ir.config_parameter'].sudo()
|
||||||
|
param = ICP.get_param(PARAM_PAYMENT_TERM)
|
||||||
|
for rec in self:
|
||||||
|
rec.customer_payment_term_id = int(param) if param else False
|
||||||
|
|
||||||
|
def _set_customer_payment_term_id(self):
|
||||||
|
ICP = self.env['ir.config_parameter'].sudo()
|
||||||
|
for rec in self:
|
||||||
|
ICP.set_param(PARAM_PAYMENT_TERM, rec.customer_payment_term_id.id or False)
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from odoo import models
|
||||||
|
from .res_config_settings import PARAM_FISCAL_POSITION, PARAM_PAYMENT_TERM
|
||||||
|
|
||||||
|
|
||||||
|
class ResPartner(models.Model):
|
||||||
|
_inherit = 'res.partner'
|
||||||
|
|
||||||
|
def default_get(self, fields_list):
|
||||||
|
res = super().default_get(fields_list)
|
||||||
|
ICP = self.env['ir.config_parameter'].sudo()
|
||||||
|
|
||||||
|
fp_id = ICP.get_param(PARAM_FISCAL_POSITION)
|
||||||
|
if fp_id:
|
||||||
|
res['property_account_position_id'] = int(fp_id)
|
||||||
|
|
||||||
|
pt_id = ICP.get_param(PARAM_PAYMENT_TERM)
|
||||||
|
if pt_id:
|
||||||
|
res['property_payment_term_id'] = int(pt_id)
|
||||||
|
|
||||||
|
return res
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<odoo>
|
||||||
|
<record id="res_config_settings_view_form_inherit_partner_defaults" model="ir.ui.view">
|
||||||
|
<field name="name">res.config.settings.view.form.inherit.partner.defaults</field>
|
||||||
|
<field name="model">res.config.settings</field>
|
||||||
|
<field name="inherit_id" ref="sale.res_config_settings_view_form"/>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<xpath expr="//div[@data-key='sale_management']" position="inside">
|
||||||
|
<h2 class="mt32">Default Customer Properties</h2>
|
||||||
|
<div class="row mt16 o_settings_container">
|
||||||
|
<div class="col-12 col-lg-6 o_setting_box">
|
||||||
|
<div class="o_setting_left_pane"/>
|
||||||
|
<div class="o_setting_right_pane">
|
||||||
|
<span class="o_form_label">Default Fiscal Position</span>
|
||||||
|
<span class="fa fa-lg fa-building-o"
|
||||||
|
title="Values set here are company-specific."
|
||||||
|
aria-label="Values set here are company-specific."
|
||||||
|
groups="base.group_multi_company"
|
||||||
|
role="img"/>
|
||||||
|
<div class="text-muted">
|
||||||
|
Applied automatically to new customers
|
||||||
|
</div>
|
||||||
|
<div class="content-group mt8">
|
||||||
|
<field name="customer_fiscal_position_id"/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-12 col-lg-6 o_setting_box">
|
||||||
|
<div class="o_setting_left_pane"/>
|
||||||
|
<div class="o_setting_right_pane">
|
||||||
|
<span class="o_form_label">Default Payment Terms</span>
|
||||||
|
<span class="fa fa-lg fa-building-o"
|
||||||
|
title="Values set here are company-specific."
|
||||||
|
aria-label="Values set here are company-specific."
|
||||||
|
groups="base.group_multi_company"
|
||||||
|
role="img"/>
|
||||||
|
<div class="text-muted">
|
||||||
|
Applied automatically to new customers
|
||||||
|
</div>
|
||||||
|
<div class="content-group mt8">
|
||||||
|
<field name="customer_payment_term_id"/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</xpath>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
</odoo>
|
||||||
Reference in New Issue
Block a user