Updated analytic_account/invoice/purchase/sale to commited version

This commit is contained in:
Guillem Barba 2016-09-28 18:03:32 +02:00
parent 763dedd41c
commit 75921cd589
5 changed files with 148 additions and 147 deletions

View File

@ -7,12 +7,9 @@ issue5104
review19141003
Index: trytond/trytond/modules/analytic_account/account.py
===================================================================
diff -r 0cd556f1c82c account.py
--- a/trytond/trytond/modules/analytic_account/account.py Sun Mar 13 16:19:22 2016 +0100
+++ b/trytond/trytond/modules/analytic_account/account.py Tue Apr 26 18:24:04 2016 +0200
diff -r 4563c00a165b account.py
--- a/trytond/trytond/modules/analytic_account/account.py Mon Nov 02 15:30:50 2015 +0100
+++ b/trytond/trytond/modules/analytic_account/account.py Wed Sep 28 17:02:53 2016 +0200
@@ -8,7 +8,7 @@
from trytond import backend
from trytond.model import ModelView, ModelSQL, fields, Unique
@ -21,7 +18,7 @@ diff -r 0cd556f1c82c account.py
+from trytond.pyson import Eval, If, PYSONEncoder, PYSONDecoder
from trytond.transaction import Transaction
from trytond.pool import Pool
@@ -22,7 +22,7 @@
name = fields.Char('Name', required=True, translate=True, select=True)
code = fields.Char('Code', select=True)
@ -35,36 +32,53 @@ diff -r 0cd556f1c82c account.py
], 'Type', required=True)
root = fields.Many2One('analytic_account.account', 'Root', select=True,
domain=[
+ ('company', '=', Eval('company')),
+ ('company', '=', Eval('company', -1)),
('parent', '=', None),
('type', '=', 'root'),
],
@@ -40,7 +41,7 @@
@@ -40,15 +41,22 @@
'invisible': Eval('type') == 'root',
'required': Eval('type') != 'root',
},
- depends=['type'])
+ depends=['company', 'type'])
parent = fields.Many2One('analytic_account.account', 'Parent', select=True,
domain=[('parent', 'child_of', Eval('root'))],
- domain=[('parent', 'child_of', Eval('root'))],
+ domain=['OR',
+ ('root', '=', Eval('root', -1)),
+ ('parent', '=', None),
+ ],
states={
@@ -311,19 +312,26 @@
'invisible': Eval('type') == 'root',
'required': Eval('type') != 'root',
},
depends=['root', 'type'])
- childs = fields.One2Many('analytic_account.account', 'parent', 'Children')
+ childs = fields.One2Many('analytic_account.account', 'parent', 'Children',
+ domain=[
+ ('company', '=', Eval('company', -1)),
+ ],
+ depends=['company'])
balance = fields.Function(fields.Numeric('Balance',
digits=(16, Eval('currency_digits', 1)), depends=['currency_digits']),
'get_balance')
@@ -311,7 +319,14 @@
__name__ = 'analytic.account.entry'
origin = fields.Reference('Origin', selection='get_origin', select=True)
root = fields.Many2One('analytic_account.account', 'Root Analytic',
- domain=[('type', '=', 'root')])
+ domain=[
+ ('company', '=', Eval('company')),
+ If(~Eval('company'),
+ # No constraint if the origin is not set
+ (),
+ ('company', '=', Eval('company', -1))),
+ ('type', '=', 'root'),
+ ],
+ depends=['company'])
account = fields.Many2One('analytic_account.account', 'Account',
ondelete='RESTRICT',
states={
'required': Eval('required', False),
},
domain=[
+ ('company', '=', Eval('company')),
@@ -321,9 +336,11 @@
('root', '=', Eval('root')),
('type', '=', 'normal'),
],
@ -74,53 +88,41 @@ diff -r 0cd556f1c82c account.py
'on_change_with_required')
+ company = fields.Function(fields.Many2One('company.company', 'Company'),
+ 'on_change_with_company', searcher='search_company')
@classmethod
def __register__(cls, module_name):
@@ -386,12 +394,27 @@
@@ -386,6 +403,13 @@
return self.root.mandatory
return False
+ @classmethod
+ def default_company(cls):
+ return Transaction().context.get('company')
+
+ def on_change_with_company(self, name=None):
+ return Transaction().context.get('company')
+ return None
+
+ @classmethod
+ def search_company(cls, name, clause):
+ raise NotImplementedError()
+ return []
+
class AnalyticMixin(ModelSQL):
analytic_accounts = fields.One2Many('analytic.account.entry', 'origin',
'Analytic Accounts',
size=Eval('analytic_accounts_size', 0),
+ domain=[
+ ('company', If(Eval('context', {}).contains('company'), '=', '!='),
+ Eval('context', {}).get('company', -1)),
+ ],
depends=['analytic_accounts_size'])
analytic_accounts_size = fields.Function(fields.Integer(
'Analytic Accounts Size'), 'get_analytic_accounts_size')
@@ -427,13 +450,19 @@
@@ -427,13 +451,21 @@
where=entry.selection == selection_id))
handler.drop_column('analytic_accounts')
- @staticmethod
- def default_analytic_accounts():
+ @classmethod
+ def analytic_accounts_domain(cls):
+ return PYSONDecoder(Transaction().context).decode(
+ context = Transaction().context.copy()
+ context['context'] = context
+ return PYSONDecoder(context).decode(
+ PYSONEncoder().encode(cls.analytic_accounts.domain))
+
+ @classmethod
+ def default_analytic_accounts(cls):
pool = Pool()
AnalyticAccount = pool.get('analytic_account.account')
accounts = []
- root_accounts = AnalyticAccount.search([
+ root_accounts = AnalyticAccount.search(
@ -128,10 +130,10 @@ diff -r 0cd556f1c82c account.py
('parent', '=', None),
])
for account in root_accounts:
@@ -443,11 +472,14 @@
@@ -443,11 +475,14 @@
})
return accounts
- @staticmethod
- def default_analytic_accounts_size():
+ @classmethod
@ -143,10 +145,10 @@ diff -r 0cd556f1c82c account.py
+ cls.analytic_accounts_domain() + [
+ ('type', '=', 'root'),
+ ]))
@classmethod
def get_analytic_accounts_size(cls, records, name):
@@ -464,12 +496,17 @@
@@ -464,12 +499,17 @@
"Check that all mandatory root entries are defined in entries"
pool = Pool()
Account = pool.get('analytic_account.account')
@ -165,41 +167,10 @@ diff -r 0cd556f1c82c account.py
if not mandatory_roots <= analytic_roots:
cls.raise_user_error('root_account', {
'name': analytic.rec_name,
diff -r 0cd556f1c82c account.xml
--- a/trytond/trytond/modules/analytic_account/account.xml Sun Mar 13 16:19:22 2016 +0100
+++ b/trytond/trytond/modules/analytic_account/account.xml Tue Apr 26 18:24:04 2016 +0200
@@ -124,5 +124,27 @@
<field name="type">tree</field>
<field name="name">analytic_account_entry_tree</field>
</record>
+
+ <record model="ir.rule.group" id="rule_group_account">
+ <field name="model" search="[('model', '=', 'analytic_account.account')]"/>
+ <field name="global_p" eval="True"/>
+ </record>
+ <record model="ir.rule" id="rule_account1">
+ <field name="domain"
+ eval="[('company', '=', Eval('user', {}).get('company', None))]"
+ pyson="1"/>
+ <field name="rule_group" ref="rule_group_account"/>
+ </record>
+
+ <record model="ir.rule.group" id="rule_group_account_entry">
+ <field name="model" search="[('model', '=', 'analytic.account.entry')]"/>
+ <field name="global_p" eval="True"/>
+ </record>
+ <record model="ir.rule" id="rule_account_entry1">
+ <field name="domain"
+ eval="[('company', '=', Eval('user', {}).get('company', None))]"
+ pyson="1"/>
+ <field name="rule_group" ref="rule_group_account_entry"/>
+ </record>
</data>
</tryton>
diff -r 0cd556f1c82c line.py
--- a/trytond/trytond/modules/analytic_account/line.py Sun Mar 13 16:19:22 2016 +0100
+++ b/trytond/trytond/modules/analytic_account/line.py Tue Apr 26 18:24:04 2016 +0200
@@ -24,7 +24,7 @@
diff -r 4563c00a165b line.py
--- a/trytond/trytond/modules/analytic_account/line.py Mon Nov 02 15:30:50 2015 +0100
+++ b/trytond/trytond/modules/analytic_account/line.py Wed Sep 28 17:02:53 2016 +0200
@@ -25,7 +25,7 @@
currency_digits = fields.Function(fields.Integer('Currency Digits'),
'on_change_with_currency_digits')
company = fields.Function(fields.Many2One('company.company', 'Company'),
@ -208,10 +179,10 @@ diff -r 0cd556f1c82c line.py
account = fields.Many2One('analytic_account.account', 'Account',
required=True, select=True, domain=[
('type', '!=', 'view'),
@@ -104,6 +104,10 @@
@@ -106,6 +106,10 @@
if self.move_line:
return self.move_line.account.company.id
+ @classmethod
+ def search_company(cls, name, clause):
+ return [('move_line.account.company',) + tuple(clause[1:])]
@ -219,22 +190,3 @@ diff -r 0cd556f1c82c line.py
@staticmethod
def query_get(table):
'''
diff -r 0cd556f1c82c line.xml
--- a/trytond/trytond/modules/analytic_account/line.xml Sun Mar 13 16:19:22 2016 +0100
+++ b/trytond/trytond/modules/analytic_account/line.xml Tue Apr 26 18:24:04 2016 +0200
@@ -67,5 +67,15 @@
<field name="name">move_line_form</field>
</record>
+ <record model="ir.rule.group" id="rule_group_account_line">
+ <field name="model" search="[('model', '=', 'analytic_account.line')]"/>
+ <field name="global_p" eval="True"/>
+ </record>
+ <record model="ir.rule" id="rule_account_line1">
+ <field name="domain"
+ eval="[('company', '=', Eval('user', {}).get('company', None))]"
+ pyson="1"/>
+ <field name="rule_group" ref="rule_group_account_line"/>
+ </record>
</data>
</tryton>

View File

@ -8,19 +8,36 @@ issue5104
review24081002
Index: trytond/trytond/modules/analytic_invoice/invoice.py
===================================================================
--- a/trytond/trytond/modules/analytic_invoice/invoice.py
+++ b/trytond/trytond/modules/analytic_invoice/invoice.py
@@ -1,5 +1,6 @@
diff -r a840721ef787 invoice.py
--- a/trytond/trytond/modules/analytic_invoice/invoice.py Mon Nov 02 15:31:51 2015 +0100
+++ b/trytond/trytond/modules/analytic_invoice/invoice.py Wed Sep 28 17:04:21 2016 +0200
@@ -1,6 +1,8 @@
# 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, Pool
+from trytond.pyson import Eval, If
from trytond.modules.analytic_account import AnalyticMixin
@@ -61,3 +62,24 @@
@@ -11,6 +13,16 @@
class InvoiceLine(AnalyticMixin):
__name__ = 'account.invoice.line'
+ @classmethod
+ def __setup__(cls):
+ super(InvoiceLine, cls).__setup__()
+ cls.analytic_accounts.domain = [
+ ('company', '=', If(~Eval('company'),
+ Eval('context', {}).get('company', -1),
+ Eval('company', -1))),
+ ]
+ cls.analytic_accounts.depends.append('company')
+
def _credit(self):
pool = Pool()
AnalyticAccountEntry = pool.get('analytic.account.entry')
@@ -61,3 +73,22 @@
def _get_origin(cls):
origins = super(AnalyticAccountEntry, cls)._get_origin()
return origins + ['account.invoice.line']
@ -32,17 +49,14 @@ Index: trytond/trytond/modules/analytic_invoice/invoice.py
+ company = super(AnalyticAccountEntry, self).on_change_with_company(
+ name)
+ if isinstance(self.origin, InvoiceLine):
+ if self.origin.invoice:
+ return self.origin.invoice.company.id
+ elif self.origin.company:
+ return self.origin.company.id
+ company = self.origin.company.id
+ return company
+
+ @classmethod
+ def search_company(cls, name, clause):
+ domain = super(AnalyticAccountEntry, cls).search_company(name, clause),
+ return ['OR',
+ [('origin.company',) + tuple(clause[1:]) +
+ tuple(('account.invoice.line',))],
+ [('origin.invoice.company',) + tuple(clause[1:]) +
+ tuple(('account.invoice.line',))]]
+ domain,
+ (('origin.company',) + tuple(clause[1:]) +
+ ('account.invoice.line',)),
+ ]

View File

@ -2,16 +2,38 @@
# User Sergi Almacellas Abellana <sergi@koolpi.com>
Add company domain on analytic entries
issue5104
issue5104
review17201002
Index: trytond/trytond/modules/analytic_purchase/purchase.py
===================================================================
diff -r 2ce8025167de purchase.py
--- a/trytond/trytond/modules/analytic_purchase/purchase.py Mon Nov 02 15:33:03 2015 +0100
+++ b/trytond/trytond/modules/analytic_purchase/purchase.py Wed Sep 28 17:09:30 2016 +0200
@@ -2,6 +2,7 @@
# this repository contains the full copyright notices and license terms.
from trytond.model import fields
from trytond.pool import Pool, PoolMeta
+from trytond.pyson import Eval, If
--- a/trytond/trytond/modules/analytic_purchase/purchase.py
+++ b/trytond/trytond/modules/analytic_purchase/purchase.py
@@ -79,3 +79,22 @@
from trytond.modules.analytic_account import AnalyticMixin
@@ -46,6 +47,15 @@
class PurchaseLine(AnalyticMixin):
__name__ = 'purchase.line'
+ @classmethod
+ def __setup__(cls):
+ super(PurchaseLine, cls).__setup__()
+ cls.analytic_accounts.domain = [
+ ('company', '=', If(~Eval('_parent_purchase'),
+ Eval('context', {}).get('company', -1),
+ Eval('_parent_purchase', {}).get('company', -1))),
+ ]
+
def get_invoice_line(self, invoice_type):
pool = Pool()
AnalyticAccountEntry = pool.get('analytic.account.entry')
@@ -79,3 +89,22 @@
and self.origin.purchase.state in ['cancel', 'draft']):
return False
return required
@ -22,9 +44,8 @@ Index: trytond/trytond/modules/analytic_purchase/purchase.py
+ PurchaseLine = pool.get('purchase.line')
+ company = super(AnalyticAccountEntry, self).on_change_with_company(
+ name)
+ if isinstance(self.origin, PurchaseLine):
+ if self.origin.purchase:
+ return self.origin.purchase.company.id
+ if isinstance(self.origin, PurchaseLine) and self.origin.purchase:
+ company = self.origin.purchase.company.id
+ return company
+
+ @classmethod
@ -32,6 +53,6 @@ Index: trytond/trytond/modules/analytic_purchase/purchase.py
+ domain = super(AnalyticAccountEntry, cls).search_company(name, clause)
+ return ['OR',
+ domain,
+ [('origin.purchase.company',) + tuple(clause[1:]) +
+ tuple(('purchase.line',))]]
+ (('origin.purchase.company',) + tuple(clause[1:])
+ + ('purchase.line',)),
+ ]

View File

@ -7,19 +7,35 @@ issue5104
review17991002
Index: trytond/trytond/modules/analytic_sale/sale.py
===================================================================
--- a/trytond/trytond/modules/analytic_sale/sale.py
+++ b/trytond/trytond/modules/analytic_sale/sale.py
@@ -1,5 +1,6 @@
diff -r cb4e222d5c45 sale.py
--- a/trytond/trytond/modules/analytic_sale/sale.py Mon Nov 02 15:34:18 2015 +0100
+++ b/trytond/trytond/modules/analytic_sale/sale.py Wed Sep 28 17:06:51 2016 +0200
@@ -1,6 +1,8 @@
# 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 Pool, PoolMeta
+from trytond.pyson import Eval, If
from trytond.modules.analytic_account import AnalyticMixin
@@ -32,3 +33,22 @@
@@ -11,6 +13,15 @@
class SaleLine(AnalyticMixin):
__name__ = 'sale.line'
+ @classmethod
+ def __setup__(cls):
+ super(SaleLine, cls).__setup__()
+ cls.analytic_accounts.domain = [
+ ('company', '=', If(~Eval('_parent_sale', {}),
+ Eval('context', {}).get('company', -1),
+ Eval('_parent_sale', {}).get('company', -1))),
+ ]
+
def get_invoice_line(self, invoice_type):
pool = Pool()
AnalyticAccountEntry = pool.get('analytic.account.entry')
@@ -32,3 +43,21 @@
def _get_origin(cls):
origins = super(AnalyticAccountEntry, cls)._get_origin()
return origins + ['sale.line']
@ -30,16 +46,14 @@ Index: trytond/trytond/modules/analytic_sale/sale.py
+ SaleLine = pool.get('sale.line')
+ company = super(AnalyticAccountEntry, self).on_change_with_company(
+ name)
+ if isinstance(self.origin, SaleLine):
+ if self.origin.sale:
+ return self.origin.sale.company.id
+ if isinstance(self.origin, SaleLine) and self.origin.sale:
+ company = self.origin.sale.company.id
+ return company
+
+ @classmethod
+ def search_company(cls, name, clause):
+ domain = super(AnalyticAccountEntry, cls).search_company(name, clause)
+ domain = super(AnalyticAccountEntry, cls).search_company(name, clause),
+ return ['OR',
+ domain,
+ [('origin.sale.company',) + tuple(clause[1:]) +
+ tuple(('sale.line',))]]
+ ('origin.sale.company',) + tuple(clause[1:]) + ('sale.line',),
+ ]

8
series
View File

@ -1,4 +1,8 @@
account_move_line_rule.diff
analytic_account.diff
analytic_invoice.diff
analytic_sale.diff
analytic_purchase.diff
issue154_316.diff
issue10467.diff
issue130_392_10919.diff
@ -33,10 +37,6 @@ issue23901002_1.diff
issue17881002_1.diff
workflow-performance.diff
account_chart_speedup.diff
analytic_account.diff
analytic_invoice.diff
analytic_sale.diff
analytic_purchase.diff
tax_active_invisible.diff
account_product_rules.diff
issue5558.diff