From b774e0419119b46304a7d1f52a47d0d81275f866 Mon Sep 17 00:00:00 2001 From: Guillem Barba Date: Wed, 28 Sep 2016 14:50:13 +0200 Subject: [PATCH] Updated analytic_account/invoice/purchase/sale to commited version --- analytic_account.diff | 99 +++++++++++++++++------------------------- analytic_invoice.diff | 46 +++++++++++++------- analytic_purchase.diff | 45 ++++++++++++++----- analytic_sale.diff | 42 ++++++++++++------ 4 files changed, 132 insertions(+), 100 deletions(-) diff --git a/analytic_account.diff b/analytic_account.diff index e5f7916..2f52167 100644 --- a/analytic_account.diff +++ b/analytic_account.diff @@ -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 cc5593b01647 account.py +--- a/trytond/trytond/modules/analytic_account/account.py Wed May 11 11:34:37 2016 +0200 ++++ b/trytond/trytond/modules/analytic_account/account.py Wed Sep 28 13:57:57 2016 +0200 @@ -8,7 +8,7 @@ from trytond import backend from trytond.model import ModelView, ModelSQL, fields, Unique @@ -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'), ], @@ -77,35 +91,21 @@ diff -r 0cd556f1c82c account.py @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') @@ -113,7 +113,9 @@ diff -r 0cd556f1c82c account.py - 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 @@ -128,7 +130,7 @@ diff -r 0cd556f1c82c account.py ('parent', '=', None), ]) for account in root_accounts: -@@ -443,11 +472,14 @@ +@@ -443,11 +475,14 @@ }) return accounts @@ -146,7 +148,7 @@ diff -r 0cd556f1c82c account.py @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,9 +167,9 @@ diff -r 0cd556f1c82c account.py if not mandatory_roots <= analytic_roots: cls.raise_user_error('root_account', { 'name': analytic.rec_name, -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 +diff -r cc5593b01647 line.py +--- a/trytond/trytond/modules/analytic_account/line.py Wed May 11 11:34:37 2016 +0200 ++++ b/trytond/trytond/modules/analytic_account/line.py Wed Sep 28 13:57:57 2016 +0200 @@ -24,7 +24,7 @@ currency_digits = fields.Function(fields.Integer('Currency Digits'), 'on_change_with_currency_digits') @@ -188,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 @@ - move_line_form - - -+ -+ -+ -+ -+ -+ -+ -+ - - diff --git a/analytic_invoice.diff b/analytic_invoice.diff index 61b04af..043e034 100644 --- a/analytic_invoice.diff +++ b/analytic_invoice.diff @@ -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 5d64f58a9c9b invoice.py +--- a/trytond/trytond/modules/analytic_invoice/invoice.py Wed May 11 11:48:47 2016 +0200 ++++ b/trytond/trytond/modules/analytic_invoice/invoice.py Wed Sep 28 14:43:36 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 @@ + +@@ -10,6 +12,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',)), ++ ] diff --git a/analytic_purchase.diff b/analytic_purchase.diff index ec55380..f2b20d4 100644 --- a/analytic_purchase.diff +++ b/analytic_purchase.diff @@ -2,16 +2,38 @@ # User Sergi Almacellas Abellana Add company domain on analytic entries -issue5104 +issue5104 review17201002 -Index: trytond/trytond/modules/analytic_purchase/purchase.py -=================================================================== +diff -r 8fda42e64b7a purchase.py +--- a/trytond/trytond/modules/analytic_purchase/purchase.py Wed May 11 12:01:56 2016 +0200 ++++ b/trytond/trytond/modules/analytic_purchase/purchase.py Wed Sep 28 14:47:26 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): + 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',)), ++ ] diff --git a/analytic_sale.diff b/analytic_sale.diff index 07cbb2d..0e7ec0a 100644 --- a/analytic_sale.diff +++ b/analytic_sale.diff @@ -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 1241acbd3ec3 sale.py +--- a/trytond/trytond/modules/analytic_sale/sale.py Wed May 11 11:56:32 2016 +0200 ++++ b/trytond/trytond/modules/analytic_sale/sale.py Wed Sep 28 14:49:23 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 @@ + +@@ -10,6 +12,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): + 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',), ++ ]