2014-12-02 12:54:59 +01:00
|
|
|
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
|
|
|
|
# this repository contains the full copyright notices and license terms.
|
2015-02-26 12:50:41 +01:00
|
|
|
from trytond.model import fields
|
2021-12-11 17:58:42 +01:00
|
|
|
from trytond.modules.analytic_account import AnalyticMixin
|
2012-09-24 22:17:41 +02:00
|
|
|
from trytond.pool import Pool, PoolMeta
|
2022-04-11 22:29:29 +02:00
|
|
|
from trytond.pyson import Eval
|
2012-09-24 22:17:41 +02:00
|
|
|
|
2008-11-14 10:39:13 +01:00
|
|
|
|
2018-06-26 19:11:45 +02:00
|
|
|
class PurchaseLine(AnalyticMixin, metaclass=PoolMeta):
|
2012-09-24 22:17:41 +02:00
|
|
|
__name__ = 'purchase.line'
|
2008-12-05 13:26:25 +01:00
|
|
|
|
2016-09-27 19:37:51 +02:00
|
|
|
@classmethod
|
|
|
|
|
def __setup__(cls):
|
|
|
|
|
super(PurchaseLine, cls).__setup__()
|
|
|
|
|
cls.analytic_accounts.domain = [
|
2022-04-11 22:29:29 +02:00
|
|
|
('company', '=', Eval('company', -1)),
|
2016-09-27 19:37:51 +02:00
|
|
|
]
|
2017-03-13 23:08:17 +01:00
|
|
|
cls.analytic_accounts.states = {
|
|
|
|
|
'invisible': Eval('type') != 'line',
|
|
|
|
|
'readonly': Eval('purchase_state') != 'draft',
|
|
|
|
|
}
|
2016-09-27 19:37:51 +02:00
|
|
|
|
2016-03-20 22:58:42 +01:00
|
|
|
def get_invoice_line(self):
|
2015-01-02 14:04:56 +01:00
|
|
|
pool = Pool()
|
|
|
|
|
AnalyticAccountEntry = pool.get('analytic.account.entry')
|
2008-12-05 13:26:25 +01:00
|
|
|
|
2016-03-20 22:58:42 +01:00
|
|
|
invoice_lines = super(PurchaseLine, self).get_invoice_line()
|
2012-09-24 22:17:41 +02:00
|
|
|
for invoice_line in invoice_lines:
|
2015-01-02 14:04:56 +01:00
|
|
|
new_entries = AnalyticAccountEntry.copy(self.analytic_accounts,
|
|
|
|
|
default={
|
|
|
|
|
'origin': None,
|
|
|
|
|
})
|
|
|
|
|
invoice_line.analytic_accounts = new_entries
|
2012-09-24 22:17:41 +02:00
|
|
|
return invoice_lines
|
2008-11-14 01:38:47 +01:00
|
|
|
|
|
|
|
|
|
2018-06-26 19:11:45 +02:00
|
|
|
class AnalyticAccountEntry(metaclass=PoolMeta):
|
2015-01-02 14:04:56 +01:00
|
|
|
__name__ = 'analytic.account.entry'
|
2008-11-14 01:38:47 +01:00
|
|
|
|
2012-09-24 22:17:41 +02:00
|
|
|
@classmethod
|
2015-01-02 14:04:56 +01:00
|
|
|
def _get_origin(cls):
|
|
|
|
|
origins = super(AnalyticAccountEntry, cls)._get_origin()
|
|
|
|
|
return origins + ['purchase.line']
|
2015-02-26 12:50:41 +01:00
|
|
|
|
2016-09-27 19:37:51 +02:00
|
|
|
@fields.depends('origin')
|
|
|
|
|
def on_change_with_company(self, name=None):
|
|
|
|
|
pool = Pool()
|
|
|
|
|
PurchaseLine = pool.get('purchase.line')
|
2023-03-26 09:49:00 +02:00
|
|
|
company = super().on_change_with_company(name)
|
2016-09-27 19:37:51 +02:00
|
|
|
if isinstance(self.origin, PurchaseLine) and self.origin.purchase:
|
2023-03-26 09:49:00 +02:00
|
|
|
company = self.origin.purchase.company
|
2016-09-27 19:37:51 +02:00
|
|
|
return company
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def search_company(cls, name, clause):
|
|
|
|
|
domain = super(AnalyticAccountEntry, cls).search_company(name, clause)
|
2023-08-02 20:35:13 +02:00
|
|
|
if domain:
|
|
|
|
|
domain = ['OR', domain]
|
|
|
|
|
domain.append(
|
2023-02-16 10:39:30 +01:00
|
|
|
('origin.purchase.' + clause[0],
|
2023-08-02 20:35:13 +02:00
|
|
|
*clause[1:3], 'purchase.line', *clause[3:]))
|
|
|
|
|
return domain
|