Add origin on move line and product and category on analytic rule

issue8074
issue8075
review62421002
This commit is contained in:
Cédric Krier
2019-03-03 23:06:25 +01:00
parent 2865878ae4
commit a60c13d227
10 changed files with 99 additions and 2 deletions
+2
View File
@@ -1,3 +1,5 @@
* Add product and category on analytic rule
Version 5.0.0 - 2018-10-01
* Bug fixes (see mercurial logs for details)
* Remove support for Python 2.7
+5
View File
@@ -5,6 +5,7 @@ from trytond.pool import Pool
from . import product
from . import configuration
from . import account
from . import analytic_account
def register():
@@ -21,6 +22,10 @@ def register():
configuration.Configuration,
configuration.ConfigurationDefaultAccount,
module='account_product', type_='model')
Pool.register(
account.MoveLine,
analytic_account.Rule,
module='account_product', type_='model', depends=['analytic_account'])
Pool.register(
account.CreateChart,
module='account_product', type_='wizard')
+26 -2
View File
@@ -5,8 +5,6 @@ from trytond.pyson import Eval
from trytond.model import fields
from trytond.transaction import Transaction
__all__ = ['CreateChart', 'CreateChartProperties']
class CreateChartProperties(metaclass=PoolMeta):
__name__ = 'account.create_chart.properties'
@@ -44,3 +42,29 @@ class CreateChart(metaclass=PoolMeta):
getattr(self.properties, name, None))
config.save()
return state
class MoveLine(metaclass=PoolMeta):
__name__ = 'account.move.line'
@property
def product(self):
pass
@property
def rule_pattern(self):
def parents(categories):
for category in categories:
while category:
yield category
category = category.parent
pattern = super().rule_pattern
if self.product:
pattern['product'] = self.product.id
pattern['product_categories'] = [
c.id for c in parents(self.product.categories_all)]
else:
pattern['product'] = None
pattern['product_categories'] = []
return pattern
+21
View File
@@ -0,0 +1,21 @@
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
from trytond.model import fields
from trytond.pool import PoolMeta
class Rule(metaclass=PoolMeta):
__name__ = 'analytic_account.rule'
product = fields.Many2One('product.product', "Product", ondelete='CASCADE')
product_category = fields.Many2One(
'product.category', "Product Category", ondelete='CASCADE')
def match(self, pattern):
if 'product_categories' in pattern:
pattern = pattern.copy()
categories = pattern.pop('product_categories')
if (self.product_category is not None
and self.product_category.id not in categories):
return False
return super().match(pattern)
+18
View File
@@ -0,0 +1,18 @@
<?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. -->
<tryton>
<data depends="analytic_account">
<record model="ir.ui.view" id="analytic_account_rule_view_list">
<field name="model">analytic_account.rule</field>
<field name="inherit" ref="analytic_account.rule_view_list"/>
<field name="name">analytic_account_rule_list</field>
</record>
<record model="ir.ui.view" id="analytic_account_rule_view_form">
<field name="model">analytic_account.rule</field>
<field name="inherit" ref="analytic_account.rule_view_form"/>
<field name="name">analytic_account_rule_form</field>
</record>
</data>
</tryton>
+2
View File
@@ -51,6 +51,7 @@ for dep in info.get('depends', []):
requires.append(get_require_version('trytond_%s' % dep))
requires.append(get_require_version('trytond'))
tests_require = [get_require_version('trytond_analytic_account')]
dependency_links = []
if minor_version % 2:
dependency_links.append('https://trydevpi.tryton.org/')
@@ -118,4 +119,5 @@ setup(name=name,
""",
test_suite='tests',
test_loader='trytond.test_loader:Loader',
tests_require=tests_require,
)
+1
View File
@@ -15,6 +15,7 @@ from trytond.modules.account.tests import create_chart
class AccountProductTestCase(ModuleTestCase):
'Test AccountProduct module'
module = 'account_product'
extras = ['analytic_account']
@with_transaction()
def test_account_used(self):
+3
View File
@@ -5,8 +5,11 @@ depends:
company
ir
product
extras_depend:
analytic_account
xml:
product.xml
configuration.xml
account.xml
message.xml
analytic_account.xml
+12
View File
@@ -0,0 +1,12 @@
<?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="//field[@name='journal']" position="after">
<newline/>
<label name="product"/>
<field name="product"/>
<label name="product_category"/>
<field name="product_category"/>
</xpath>
</data>
+9
View File
@@ -0,0 +1,9 @@
<?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="//field[@name='journal']" position="after">
<field name="product"/>
<field name="product_category"/>
</xpath>
</data>