fix some isues and add fields on party
This commit is contained in:
parent
0ada16cba2
commit
5723fb9475
|
@ -9,4 +9,6 @@ def register():
|
|||
invoice.AccountInvoiceLine,
|
||||
invoice.AccountInvoiceAccountRule,
|
||||
invoice.AccountInvoiceAccountRuleLine,
|
||||
invoice.Party,
|
||||
invoice.PartyAccount,
|
||||
module='account_invoice_rule', type_='model')
|
||||
|
|
111
invoice.py
111
invoice.py
|
@ -1,57 +1,68 @@
|
|||
from trytond.model import MatchMixin, ModelSQL, ModelView, Workflow, fields
|
||||
from trytond.model import MatchMixin, ModelSQL, ModelView, fields
|
||||
from trytond.pool import Pool, PoolMeta
|
||||
from trytond.transaction import Transaction
|
||||
|
||||
from trytond.transaction import Transaction
|
||||
from trytond.pyson import Eval
|
||||
|
||||
|
||||
class AccountInvoiceAccountRule(ModelSQL, ModelView):
|
||||
"""" Account Invoice Account Rule """
|
||||
"""Account Invoice Account Rule"""
|
||||
__name__ = 'account.invoice.account.rule'
|
||||
|
||||
name = fields.Char('Name')
|
||||
company = fields.Many2One('company.company', 'Company')
|
||||
name = fields.Char('Name', required=True)
|
||||
company = fields.Many2One('company.company', 'Company', required=True)
|
||||
lines = fields.One2Many('account.invoice.account.rule.line', 'rule', 'Lines')
|
||||
|
||||
@staticmethod
|
||||
def default_company():
|
||||
return Transaction().context.get('company') or None
|
||||
|
||||
def compute(self, pattern):
|
||||
for line in self.lines:
|
||||
if line.match(pattern):
|
||||
return line.target_account
|
||||
|
||||
return pattern.get('origin_account')
|
||||
|
||||
|
||||
class AccountInvoiceAccountRuleLine(ModelSQL, ModelView, MatchMixin):
|
||||
"""" Account Invoice Account Rule Line"""
|
||||
"""Account Invoice Account Rule Line"""
|
||||
__name__ = 'account.invoice.account.rule.line'
|
||||
|
||||
rule = fields.Many2One('account.invoice.account.rule', 'Rule')
|
||||
rule = fields.Many2One('account.invoice.account.rule', 'Rule', required=True, ondelete='CASCADE')
|
||||
origin_account = fields.Many2One('account.account', 'Origin Account',
|
||||
domain=[('type', '!=', 'view')])
|
||||
domain=[('type', '!=', 'view')], required=True)
|
||||
target_account = fields.Many2One('account.account', 'Target Account',
|
||||
domain=[('type', '!=', 'view')])
|
||||
company = fields.Many2One('company.company', 'Company')
|
||||
domain=[('type', '!=', 'view')], required=True)
|
||||
company = fields.Function(fields.Many2One('company.company', 'Company', ),
|
||||
'on_change_with_rule')
|
||||
|
||||
def match(self, pattern):
|
||||
if 'origin_account' in pattern and pattern['origin_account'] == self.origin_account:
|
||||
return self.target_account
|
||||
return True
|
||||
return False
|
||||
|
||||
@fields.depends('rule', '_parent_rule.company')
|
||||
def on_change_with_rule(self, name=None):
|
||||
if self.rule and self.rule.company:
|
||||
return self.rule.company.id
|
||||
|
||||
@staticmethod
|
||||
def default_company():
|
||||
return Transaction().context.get('company') or None
|
||||
|
||||
class AccountInvoice(metaclass=PoolMeta):
|
||||
__name__ = 'account.invoice'
|
||||
|
||||
ruleset = fields.Many2One('account.invoice.account.rule', 'Account Rules')
|
||||
|
||||
|
||||
@classmethod
|
||||
def post(cls, invoices):
|
||||
Line = Pool().get('account.invoice.line')
|
||||
to_save = []
|
||||
for invoice in invoices:
|
||||
rule = invoice.party.customer_invoice_account_rule
|
||||
if invoice.type == 'in':
|
||||
rule = invoice.supplier_invoice_account_rule
|
||||
if not rule:
|
||||
continue
|
||||
for line in invoice.lines:
|
||||
rule = line._get_account_matching_rule()
|
||||
if not rule:
|
||||
continue
|
||||
line.account = rule.target_account
|
||||
line.on_change_account()
|
||||
pattern = line._get_account_rule_pattern()
|
||||
line.account = rule.compute(pattern)
|
||||
to_save.append(line)
|
||||
Line.save(to_save)
|
||||
super().post(invoices)
|
||||
|
@ -68,16 +79,50 @@ class AccountInvoiceLine(metaclass=PoolMeta):
|
|||
pattern['origin_account'] = self.account
|
||||
return pattern
|
||||
|
||||
def _get_account_matching_rule(self, pattern=None):
|
||||
RuleSet = Pool().get('account.invoice.account.rule')
|
||||
rulesets = RuleSet.search([])
|
||||
if not rulesets:
|
||||
return
|
||||
|
||||
ruleset = rulesets[0]
|
||||
pattern = self._get_account_rule_pattern()
|
||||
for rule in ruleset.lines:
|
||||
if rule.match(pattern):
|
||||
return rule
|
||||
class Party(metaclass=PoolMeta):
|
||||
__name__ = 'party.party'
|
||||
|
||||
customer_invoice_account_rule = fields.MultiValue(fields.Many2One(
|
||||
'account.invoice.account.rule', "Customer Account Invoice Rule",
|
||||
domain=[
|
||||
('company', '=', Eval('context', {}).get('company', -1)),
|
||||
],
|
||||
states={
|
||||
'invisible': ~Eval('context', {}).get('company'),
|
||||
}))
|
||||
|
||||
supplier_invoice_account_rule = fields.MultiValue(fields.Many2One(
|
||||
'account.invoice.account.rule', "Supplier Account Invoice Rule",
|
||||
domain=[
|
||||
('company', '=', Eval('context', {}).get('company', -1)),
|
||||
],
|
||||
states={
|
||||
'invisible': ~Eval('context', {}).get('company'),
|
||||
}))
|
||||
|
||||
@classmethod
|
||||
def multivalue_model(cls, field):
|
||||
pool = Pool()
|
||||
if field in {'customer_invoice_account_rule', 'supplier_invoice_account_rule'}:
|
||||
return pool.get('party.party.account')
|
||||
return super(Party, cls).multivalue_model(field)
|
||||
|
||||
|
||||
class PartyAccount(metaclass=PoolMeta):
|
||||
"""Party Account"""
|
||||
__name__ = 'party.party.account'
|
||||
|
||||
customer_invoice_account_rule = fields.Many2One(
|
||||
'account.invoice.account.rule', "Customer Invoice Account Rule",
|
||||
domain=[
|
||||
('company', '=', Eval('company', -1)),
|
||||
],
|
||||
depends=['company'])
|
||||
|
||||
supplier_invoice_account_rule = fields.Many2One(
|
||||
'account.invoice.account.rule', "Supplier Invoice Account Rule",
|
||||
domain=[
|
||||
('company', '=', Eval('company', -1)),
|
||||
],
|
||||
depends=['company'])
|
||||
|
|
42
invoice.xml
42
invoice.xml
|
@ -42,9 +42,14 @@ this repository contains the full copyright notices and license terms. -->
|
|||
<field name="name">invoice_account_rule_line_tree</field>
|
||||
</record>
|
||||
|
||||
<menuitem parent="account.menu_account_configuration" action="act_invoice_account_rule_form"
|
||||
id="menu_invoice_account_rule_form" sequence="3"/>
|
||||
<record model="ir.ui.view" id="party_view_form">
|
||||
<field name="model">party.party</field>
|
||||
<field name="inherit" ref="party.party_view_form"/>
|
||||
<field name="name">party_form</field>
|
||||
</record>
|
||||
|
||||
<menuitem parent="account.menu_account_tree" action="act_invoice_account_rule_form"
|
||||
id="menu_invoice_account_rule_form" sequence="3"/>
|
||||
|
||||
<record model="ir.rule.group" id="rule_group_invoice_account_rule">
|
||||
<field name="name">Invoice Account Rule</field>
|
||||
|
@ -59,5 +64,38 @@ this repository contains the full copyright notices and license terms. -->
|
|||
<field name="rule_group" ref="rule_group_invoice_account_rule"/>
|
||||
</record>
|
||||
|
||||
<record model="ir.model.access" id="access_account_invoice_rule_group">
|
||||
<field name="model" search="[('model', '=', 'account.invoice.account.rule')]"/>
|
||||
<field name="perm_read" eval="False"/>
|
||||
<field name="perm_write" eval="False"/>
|
||||
<field name="perm_create" eval="False"/>
|
||||
<field name="perm_delete" eval="False"/>
|
||||
</record>
|
||||
<record model="ir.model.access" id="access_account_invoice_account_rule">
|
||||
<field name="model" search="[('model', '=', 'account.invoice.account.rule')]"/>
|
||||
<field name="group" ref="account.group_account"/>
|
||||
<field name="perm_read" eval="True"/>
|
||||
<field name="perm_write" eval="True"/>
|
||||
<field name="perm_create" eval="True"/>
|
||||
<field name="perm_delete" eval="True"/>
|
||||
</record>
|
||||
|
||||
<record model="ir.model.access" id="access_account_invoice_rule_line_group">
|
||||
<field name="model" search="[('model', '=', 'account.invoice.account.rule.line')]"/>
|
||||
<field name="perm_read" eval="False"/>
|
||||
<field name="perm_write" eval="False"/>
|
||||
<field name="perm_create" eval="False"/>
|
||||
<field name="perm_delete" eval="False"/>
|
||||
</record>
|
||||
|
||||
<record model="ir.model.access" id="access_account_invoice_account_rule_line">
|
||||
<field name="model" search="[('model', '=', 'account.invoice.account.rule.line')]"/>
|
||||
<field name="group" ref="account.group_account"/>
|
||||
<field name="perm_read" eval="True"/>
|
||||
<field name="perm_write" eval="True"/>
|
||||
<field name="perm_create" eval="True"/>
|
||||
<field name="perm_delete" eval="True"/>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</tryton>
|
60
locale/ca.po
60
locale/ca.po
|
@ -4,7 +4,7 @@ msgstr "Content-Type: text/plain; charset=utf-8\n"
|
|||
|
||||
msgctxt "field:account.invoice,ruleset:"
|
||||
msgid "Account Rules"
|
||||
msgstr "Reglas cuentas factura"
|
||||
msgstr "Regla compte factura"
|
||||
|
||||
msgctxt "field:account.invoice.account.rule,company:"
|
||||
msgid "Company"
|
||||
|
@ -12,11 +12,11 @@ msgstr "Empresa"
|
|||
|
||||
msgctxt "field:account.invoice.account.rule,create_date:"
|
||||
msgid "Create Date"
|
||||
msgstr "Fecha de creación"
|
||||
msgstr "Data creació"
|
||||
|
||||
msgctxt "field:account.invoice.account.rule,create_uid:"
|
||||
msgid "Create User"
|
||||
msgstr "Usuario de creación"
|
||||
msgstr "Usuari creació"
|
||||
|
||||
msgctxt "field:account.invoice.account.rule,id:"
|
||||
msgid "ID"
|
||||
|
@ -24,23 +24,23 @@ msgstr "Identificador"
|
|||
|
||||
msgctxt "field:account.invoice.account.rule,lines:"
|
||||
msgid "Lines"
|
||||
msgstr "Líneas"
|
||||
msgstr "Línia"
|
||||
|
||||
msgctxt "field:account.invoice.account.rule,name:"
|
||||
msgid "Name"
|
||||
msgstr "Nombre registro"
|
||||
msgstr "Nom"
|
||||
|
||||
msgctxt "field:account.invoice.account.rule,rec_name:"
|
||||
msgid "Record Name"
|
||||
msgstr "Nombre registro"
|
||||
msgstr "Nom"
|
||||
|
||||
msgctxt "field:account.invoice.account.rule,write_date:"
|
||||
msgid "Write Date"
|
||||
msgstr "Fecha modificación"
|
||||
msgstr "Data modificació"
|
||||
|
||||
msgctxt "field:account.invoice.account.rule,write_uid:"
|
||||
msgid "Write User"
|
||||
msgstr "Usuario modificación"
|
||||
msgstr "Usuari modificació"
|
||||
|
||||
msgctxt "field:account.invoice.account.rule.line,company:"
|
||||
msgid "Company"
|
||||
|
@ -48,11 +48,11 @@ msgstr "Empresa"
|
|||
|
||||
msgctxt "field:account.invoice.account.rule.line,create_date:"
|
||||
msgid "Create Date"
|
||||
msgstr "Fecha de creación"
|
||||
msgstr "Data de creació"
|
||||
|
||||
msgctxt "field:account.invoice.account.rule.line,create_uid:"
|
||||
msgid "Create User"
|
||||
msgstr "Usuario de creación"
|
||||
msgstr "Usuari de creació"
|
||||
|
||||
msgctxt "field:account.invoice.account.rule.line,id:"
|
||||
msgid "ID"
|
||||
|
@ -60,11 +60,11 @@ msgstr "Identificador"
|
|||
|
||||
msgctxt "field:account.invoice.account.rule.line,origin_account:"
|
||||
msgid "Origin Account"
|
||||
msgstr "Cuenta"
|
||||
msgstr "Compte"
|
||||
|
||||
msgctxt "field:account.invoice.account.rule.line,rec_name:"
|
||||
msgid "Record Name"
|
||||
msgstr "Nombre registro"
|
||||
msgstr "Nom registre"
|
||||
|
||||
msgctxt "field:account.invoice.account.rule.line,rule:"
|
||||
msgid "Rule"
|
||||
|
@ -72,32 +72,48 @@ msgstr "Regla"
|
|||
|
||||
msgctxt "field:account.invoice.account.rule.line,target_account:"
|
||||
msgid "Target Account"
|
||||
msgstr "Cuenta destino"
|
||||
msgstr "Compte desti"
|
||||
|
||||
msgctxt "field:account.invoice.account.rule.line,write_date:"
|
||||
msgid "Write Date"
|
||||
msgstr "Fecha modificación"
|
||||
msgstr "Data modificació"
|
||||
|
||||
msgctxt "field:account.invoice.account.rule.line,write_uid:"
|
||||
msgid "Write User"
|
||||
msgstr "Usuario modificación"
|
||||
msgstr "Usuari modificació"
|
||||
|
||||
msgctxt "field:party.party,customer_invoice_account_rule:"
|
||||
msgid "Customer Account Invoice Rule"
|
||||
msgstr "Regla compte factura client"
|
||||
|
||||
msgctxt "field:party.party,supplier_invoice_account_rule:"
|
||||
msgid "Supplier Account Invoice Rule"
|
||||
msgstr "Regla compte factura proveïdor"
|
||||
|
||||
msgctxt "field:party.party.account,customer_invoice_account_rule:"
|
||||
msgid "Customer Invoice Account Rule"
|
||||
msgstr "Regla compte factura client"
|
||||
|
||||
msgctxt "field:party.party.account,supplier_invoice_account_rule:"
|
||||
msgid "Supplier Invoice Account Rule"
|
||||
msgstr "Regla compte factura proveïdor"
|
||||
|
||||
msgctxt "model:account.invoice.account.rule,name:"
|
||||
msgid "\" Account Invoice Account Rule"
|
||||
msgstr "Reglas cuentas factura"
|
||||
msgid "Account Invoice Account Rule"
|
||||
msgstr "Regla compte factura"
|
||||
|
||||
msgctxt "model:account.invoice.account.rule.line,name:"
|
||||
msgid "\" Account Invoice Account Rule Line"
|
||||
msgstr "Reglas cuentas factura"
|
||||
msgid "Account Invoice Account Rule Line"
|
||||
msgstr "Regla compte factura"
|
||||
|
||||
msgctxt "model:ir.action,name:act_invoice_account_rule_form"
|
||||
msgid "Invoice Account Rules"
|
||||
msgstr "Reglas cuentas factura"
|
||||
msgstr "Regla compte factura"
|
||||
|
||||
msgctxt "model:ir.rule.group,name:rule_group_invoice_account_rule"
|
||||
msgid "Invoice Account Rule"
|
||||
msgstr "Reglas cuentas factura"
|
||||
msgstr "Regla compte factura"
|
||||
|
||||
msgctxt "model:ir.ui.menu,name:menu_invoice_account_rule_form"
|
||||
msgid "Invoice Account Rules"
|
||||
msgstr "Reglas cuentas factura"
|
||||
msgstr "Regla compte factura"
|
||||
|
|
|
@ -0,0 +1,115 @@
|
|||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "field:account.invoice.account.rule,company:"
|
||||
msgid "Company"
|
||||
msgstr "Empresa"
|
||||
|
||||
msgctxt "field:account.invoice.account.rule,create_date:"
|
||||
msgid "Create Date"
|
||||
msgstr "Fecha de creación"
|
||||
|
||||
msgctxt "field:account.invoice.account.rule,create_uid:"
|
||||
msgid "Create User"
|
||||
msgstr "Usuario de creación"
|
||||
|
||||
msgctxt "field:account.invoice.account.rule,id:"
|
||||
msgid "ID"
|
||||
msgstr "ID"
|
||||
|
||||
msgctxt "field:account.invoice.account.rule,lines:"
|
||||
msgid "Lines"
|
||||
msgstr "Líneas"
|
||||
|
||||
msgctxt "field:account.invoice.account.rule,name:"
|
||||
msgid "Name"
|
||||
msgstr "Nombre"
|
||||
|
||||
msgctxt "field:account.invoice.account.rule,rec_name:"
|
||||
msgid "Record Name"
|
||||
msgstr "Nombre del registro"
|
||||
|
||||
msgctxt "field:account.invoice.account.rule,write_date:"
|
||||
msgid "Write Date"
|
||||
msgstr "Fecha de modificación"
|
||||
|
||||
msgctxt "field:account.invoice.account.rule,write_uid:"
|
||||
msgid "Write User"
|
||||
msgstr "Usuario de modificación"
|
||||
|
||||
msgctxt "field:account.invoice.account.rule.line,company:"
|
||||
msgid "Company"
|
||||
msgstr "Empresa"
|
||||
|
||||
msgctxt "field:account.invoice.account.rule.line,create_date:"
|
||||
msgid "Create Date"
|
||||
msgstr "Fecha de creación"
|
||||
|
||||
msgctxt "field:account.invoice.account.rule.line,create_uid:"
|
||||
msgid "Create User"
|
||||
msgstr "Usuario de creación"
|
||||
|
||||
msgctxt "field:account.invoice.account.rule.line,id:"
|
||||
msgid "ID"
|
||||
msgstr "ID"
|
||||
|
||||
msgctxt "field:account.invoice.account.rule.line,origin_account:"
|
||||
msgid "Origin Account"
|
||||
msgstr "Cuenta origen"
|
||||
|
||||
msgctxt "field:account.invoice.account.rule.line,rec_name:"
|
||||
msgid "Record Name"
|
||||
msgstr "Nombre del registro"
|
||||
|
||||
msgctxt "field:account.invoice.account.rule.line,rule:"
|
||||
msgid "Rule"
|
||||
msgstr "Regla"
|
||||
|
||||
msgctxt "field:account.invoice.account.rule.line,target_account:"
|
||||
msgid "Target Account"
|
||||
msgstr "Cuenta destino"
|
||||
|
||||
msgctxt "field:account.invoice.account.rule.line,write_date:"
|
||||
msgid "Write Date"
|
||||
msgstr "Fecha de modificación"
|
||||
|
||||
msgctxt "field:account.invoice.account.rule.line,write_uid:"
|
||||
msgid "Write User"
|
||||
msgstr "Usuario de modificación"
|
||||
|
||||
msgctxt "field:party.party,customer_invoice_account_rule:"
|
||||
msgid "Customer Account Invoice Rule"
|
||||
msgstr "Regla de cuentas factura cliente"
|
||||
|
||||
msgctxt "field:party.party,supplier_invoice_account_rule:"
|
||||
msgid "Supplier Account Invoice Rule"
|
||||
msgstr "Regla de cuentas factura proveedor"
|
||||
|
||||
msgctxt "field:party.party.account,customer_invoice_account_rule:"
|
||||
msgid "Customer Invoice Account Rule"
|
||||
msgstr "Regla de cuentas factura cliente"
|
||||
|
||||
msgctxt "field:party.party.account,supplier_invoice_account_rule:"
|
||||
msgid "Supplier Invoice Account Rule"
|
||||
msgstr "Reglas de cuentas factura proveedor"
|
||||
|
||||
msgctxt "model:account.invoice.account.rule,name:"
|
||||
msgid "Account Invoice Account Rule"
|
||||
msgstr "Regla de cuentas factura"
|
||||
|
||||
msgctxt "model:account.invoice.account.rule.line,name:"
|
||||
msgid "Account Invoice Account Rule Line"
|
||||
msgstr "Línea de reglas de cuentas factura"
|
||||
|
||||
msgctxt "model:ir.action,name:act_invoice_account_rule_form"
|
||||
msgid "Invoice Account Rules"
|
||||
msgstr "Regla de cuentas factura"
|
||||
|
||||
msgctxt "model:ir.rule.group,name:rule_group_invoice_account_rule"
|
||||
msgid "Invoice Account Rule"
|
||||
msgstr "Reglas de cuentas factura"
|
||||
|
||||
msgctxt "model:ir.ui.menu,name:menu_invoice_account_rule_form"
|
||||
msgid "Invoice Account Rules"
|
||||
msgstr "Reglas de cuentas factura"
|
|
@ -51,15 +51,6 @@ Create chart of accounts::
|
|||
Create new Account::
|
||||
>>> revenue2, = revenue.duplicate()
|
||||
|
||||
Create Account Invoice Tax Rule::
|
||||
|
||||
>>> Ruleset = Model.get('account.invoice.account.rule')
|
||||
>>> rule = Ruleset()
|
||||
>>> rule.name = 'Test'
|
||||
>>> line = rule.lines.new()
|
||||
>>> line.origin_account = revenue
|
||||
>>> line.target_account = revenue2
|
||||
>>> rule.save()
|
||||
|
||||
Create tax::
|
||||
|
||||
|
@ -102,10 +93,21 @@ Create Write Off method::
|
|||
>>> writeoff_method.debit_account = expense
|
||||
>>> writeoff_method.save()
|
||||
|
||||
Create Account Invoice Tax Rule::
|
||||
|
||||
>>> Ruleset = Model.get('account.invoice.account.rule')
|
||||
>>> rule = Ruleset()
|
||||
>>> rule.name = 'Test'
|
||||
>>> line = rule.lines.new()
|
||||
>>> line.origin_account = revenue
|
||||
>>> line.target_account = revenue2
|
||||
>>> rule.save()
|
||||
|
||||
Create party::
|
||||
|
||||
>>> Party = Model.get('party.party')
|
||||
>>> party = Party(name='Party')
|
||||
>>> party.customer_invoice_account_rule = rule
|
||||
>>> party.save()
|
||||
|
||||
Create account category::
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
<?xml version="1.0"?>
|
||||
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
this repository contains the full copyright notices and license terms. -->
|
||||
<data>
|
||||
<xpath
|
||||
expr="/form/notebook/page[@id='accounting']/separator[@id='account']"
|
||||
position="after">
|
||||
<label name="customer_invoice_account_rule"/>
|
||||
<field name="customer_invoice_account_rule"/>
|
||||
<label name="supplier_invoice_account_rule"/>
|
||||
<field name="supplier_invoice_account_rule"/>
|
||||
</xpath>
|
||||
</data>
|
Loading…
Reference in New Issue