mirror of
https://gitlab.com/datalifeit/trytond-production_cost_manage
synced 2023-12-14 05:22:55 +01:00
51 lines
1.6 KiB
Python
51 lines
1.6 KiB
Python
#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.modules.cost_manage import ComposeCostSource, CostCenter
|
|
|
|
__all__ = ['Production']
|
|
|
|
__metaclass__ = PoolMeta
|
|
|
|
|
|
class Production(ComposeCostSource):
|
|
|
|
__name__ = 'production'
|
|
|
|
@fields.depends('effective_date')
|
|
def on_change_with_cost_date(self, field=None):
|
|
return getattr(self, 'effective_date', None)
|
|
|
|
def get_son_sources(self):
|
|
return self.inputs
|
|
|
|
@fields.depends('company')
|
|
def on_change_with_currency_digits(self, name=None):
|
|
if self.company:
|
|
return self.company.currency.digits
|
|
return 2
|
|
|
|
@classmethod
|
|
def _manage_input_cost(cls, productions):
|
|
|
|
cls.distribute([p.id for p in productions])
|
|
|
|
pool = Pool()
|
|
|
|
models = [pool.get('cost.manage.distribution.rule'), pool.get('cost.manage.cost.distribution')]
|
|
distributions = cls.search_details(models[1], productions, active_test=False, status='stable')
|
|
models[1].delete(distributions)
|
|
for model in models:
|
|
details = cls.search_details(model, productions, status='added')
|
|
model.write(details, dict(status='stable'))
|
|
|
|
@classmethod
|
|
def run(cls, productions):
|
|
super(Production, cls).run(productions)
|
|
cls._manage_input_cost(productions)
|
|
|
|
@classmethod
|
|
def done(cls, productions):
|
|
super(Production, cls).done(productions)
|
|
cls._manage_input_cost(productions) |