diff --git a/modules/production_work/CHANGELOG b/modules/production_work/CHANGELOG index a5b65551df..cd7469e52f 100644 --- a/modules/production_work/CHANGELOG +++ b/modules/production_work/CHANGELOG @@ -1,3 +1,4 @@ +* Display cost of works Version 6.8.0 - 2023-05-01 -------------------------- diff --git a/modules/production_work/production.py b/modules/production_work/production.py index f6e7540935..39b983f2b6 100644 --- a/modules/production_work/production.py +++ b/modules/production_work/production.py @@ -1,16 +1,10 @@ # 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 decimal import Decimal - -from sql.aggregate import Sum - from trytond.i18n import gettext from trytond.model import ModelView, Workflow, fields from trytond.model.exceptions import AccessError -from trytond.modules.product import round_price from trytond.pool import Pool, PoolMeta from trytond.pyson import Bool, Eval -from trytond.transaction import Transaction class Production(metaclass=PoolMeta): @@ -36,30 +30,10 @@ class Production(metaclass=PoolMeta): ]) def get_cost(self, name): - pool = Pool() - Work = pool.get('production.work') - Cycle = pool.get('production.work.cycle') - table = self.__table__() - work = Work.__table__() - cycle = Cycle.__table__() - cursor = Transaction().connection.cursor() - - cost = super(Production, self).get_cost(name) - - cursor.execute(*table.join(work, 'LEFT', - condition=work.production == table.id - ).join(cycle, 'LEFT', condition=cycle.work == work.id - ).select(Sum(cycle.cost), - where=(cycle.state == 'done') - & (table.id == self.id))) - cycle_cost, = cursor.fetchone() - if cycle_cost is not None: - # SQLite uses float for SUM - if not isinstance(cycle_cost, Decimal): - cycle_cost = Decimal(cycle_cost) - cost += cycle_cost - - return round_price(cost) + cost = super().get_cost(name) + for work in self.works: + cost += work.cost + return cost @classmethod @ModelView.button diff --git a/modules/production_work/tests/scenario_production_work.rst b/modules/production_work/tests/scenario_production_work.rst index a66f44ccaa..e0c7c9043a 100644 --- a/modules/production_work/tests/scenario_production_work.rst +++ b/modules/production_work/tests/scenario_production_work.rst @@ -244,6 +244,10 @@ Check production cost:: >>> production.reload() >>> production.cost Decimal('17.0000') + >>> work1.cost + Decimal('10.0000') + >>> work2.cost + Decimal('5.0000') Do the production:: diff --git a/modules/production_work/view/work_form.xml b/modules/production_work/view/work_form.xml index 3fe5289592..95cb718208 100644 --- a/modules/production_work/view/work_form.xml +++ b/modules/production_work/view/work_form.xml @@ -17,7 +17,8 @@ this repository contains the full copyright notices and license terms. -->