mirror of
https://github.com/NaN-tic/trytond-patches.git
synced 2023-12-14 06:03:03 +01:00
62 lines
2.1 KiB
Diff
62 lines
2.1 KiB
Diff
# HG changeset patch
|
|
# User Sergi Almacellas Abellana <sergi@koolpi.com>
|
|
Add company domain on analytic entries
|
|
|
|
|
|
issue5104
|
|
|
|
|
|
review24081002
|
|
|
|
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
|
|
|
|
@@ -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']
|
|
+
|
|
+ @fields.depends('origin')
|
|
+ def on_change_with_company(self, name=None):
|
|
+ pool = Pool()
|
|
+ InvoiceLine = pool.get('account.invoice.line')
|
|
+ company = super(AnalyticAccountEntry, self).on_change_with_company(
|
|
+ name)
|
|
+ if isinstance(self.origin, InvoiceLine):
|
|
+ company = self.origin.company.id
|
|
+ return company
|
|
+
|
|
+ @classmethod
|
|
+ def search_company(cls, name, clause):
|
|
+ domain = super(AnalyticAccountEntry, cls).search_company(name, clause),
|
|
+ return ['OR',
|
|
+ domain,
|
|
+ (('origin.company',) + tuple(clause[1:]) +
|
|
+ ('account.invoice.line',)),
|
|
+ ]
|