From fd4259f636b23f157b7f3ca6dc02ee8bb7345a1c Mon Sep 17 00:00:00 2001 From: Albert Cervera i Areny Date: Sat, 15 Jun 2019 02:01:30 +0200 Subject: [PATCH] Adapt to Tryton 5.2 --- __init__.py | 8 +- feed_production.py | 112 +++++++++--------------- message.xml | 31 +++++++ setup.py | 4 +- tests/scenario_farm_feed_production.rst | 27 ++---- tryton.cfg | 3 +- 6 files changed, 85 insertions(+), 100 deletions(-) create mode 100644 message.xml diff --git a/__init__.py b/__init__.py index 7897d41..5a8aff4 100644 --- a/__init__.py +++ b/__init__.py @@ -2,12 +2,12 @@ #copyright notices and license terms. from trytond.pool import Pool -from .feed_production import * +from . import feed_production def register(): Pool.register( - SupplyRequestLine, - Production, - Prescription, + feed_production.SupplyRequestLine, + feed_production.Production, + feed_production.Prescription, module='farm_feed_production', type_='model') diff --git a/feed_production.py b/feed_production.py index 55c7f16..9316b55 100644 --- a/feed_production.py +++ b/feed_production.py @@ -7,29 +7,21 @@ from trytond.model import ModelView, Workflow, fields from trytond.pool import Pool, PoolMeta from trytond.pyson import Bool, Eval, Or from trytond.transaction import Transaction +from trytond.exceptions import UserError +from trytond.i18n import gettext from trytond.modules.production.production import BOM_CHANGES from trytond.modules.production_supply_request.supply_request \ import prepare_write_vals __all__ = ['Prescription', 'Production', 'SupplyRequestLine'] -__metaclass__ = PoolMeta PRESCRIPTION_CHANGES = BOM_CHANGES[:] + ['prescription'] -class SupplyRequestLine: +class SupplyRequestLine(metaclass=PoolMeta): __name__ = 'stock.supply_request.line' - @classmethod - def __setup__(cls): - super(SupplyRequestLine, cls).__setup__() - cls._error_messages.update({ - 'to_warehouse_farm_line_not_available': ('The specified ' - 'destination warehouse in supply request "%s" is not ' - 'configured as a farm for none specie.'), - }) - def get_move(self): pool = Pool() Prescription = pool.get('farm.prescription') @@ -54,8 +46,9 @@ class SupplyRequestLine: ('farm', '=', self.request.to_warehouse.id), ]) if not farm_lines: - self.raise_user_error('to_warehouse_farm_line_not_available', - self.request.rec_name) + raise UserError(gettext('farm_feed_production.' + 'msg_to_warehouse_farm_line_not_available', + request=self.request.rec_name)) Prescription = pool.get('farm.prescription') prescription = Prescription() @@ -96,7 +89,7 @@ class SupplyRequestLine: return None -class Production: +class Production(metaclass=PoolMeta): __name__ = 'production' prescription = fields.Many2One('farm.prescription', 'Prescription', @@ -118,31 +111,7 @@ class Production: for fname2 in ('prescription', 'origin'): field.on_change.add(fname2) - cls._error_messages.update({ - 'from_supply_request_invalid_prescription': ( - 'The Production "%(production)s" has the Supply Request ' - '"%(origin)s" as origin which requires prescription, but ' - 'it has not prescription or it isn\'t the origin\'s ' - 'prescription.'), - 'invalid_input_move_prescription': ( - 'The Input Move "%(move)s" of Production "%(production)s" ' - 'is related to a different prescription than the ' - 'production.'), - 'missing_input_moves_from_prescription': ( - 'The Production "%(production)s" is related to a ' - 'prescription but the next lines of this prescription ' - 'doesn\'t appear in the Input Moves of production: ' - '%(missing_lines)s.'), - 'no_changes_allowed_prescription_confirmed': ( - 'You can\'t change the Quantity nor Uom of production ' - '"%(production)s" because it has the prescription ' - '"%(prescription)s" related and it is already confirmed.'), - 'prescription_not_confirmed': ('To assign the production ' - '"%(production)s" the prescription "%(prescription)s", ' - 'which is related to it, must to be Confirmed or Done.'), - }) - - @fields.depends(methods=['bom']) + @fields.depends(methods=['explode_bom']) def on_change_prescription(self): self.explode_bom() @@ -160,10 +129,11 @@ class Production: self.origin.product.prescription_required and not self.prescription or self.prescription != self.origin.move.prescription): - self.raise_user_error('from_supply_request_invalid_prescription', { - 'production': self.rec_name, - 'origin': self.origin.request.rec_name, - }) + raise UserError(gettext('farm_feed_production.' + 'msg_from_supply_request_invalid_prescription', + production=self.rec_name, + origin=self.origin.request.rec_name, + )) if not self.prescription: return @@ -171,18 +141,20 @@ class Production: for input_move in self.inputs: if (input_move.prescription and input_move.prescription != self.prescription): - self.raise_user_error('invalid_input_move_prescription', { - 'move': input_move.rec_name, - 'production': self.rec_name, - }) + raise UserError(gettext('farm_feed_production.' + 'msg_invalid_input_move_prescription', + move=input_move.rec_name, + production=self.rec_name, + )) if input_move.prescription: prescription_lines.remove(input_move.origin) if prescription_lines: - self.raise_user_error('missing_input_moves_from_prescription', { - 'production': self.rec_name, - 'missing_lines': ", ".join(l.rec_name - for l in prescription_lines), - }) + raise UserError(gettext('farm_feed_production.' + 'msg_missing_input_moves_from_prescription', + production=self.rec_name, + missing_lines=", ".join(l.rec_name for l in + prescription_lines), + )) def explode_bom(self): pool = Pool() @@ -273,10 +245,11 @@ class Production: for production in productions: if production.prescription: if production.prescription.state not in ('confirmed', 'done'): - cls.raise_user_error('prescription_not_confirmed', { - 'prescription': production.prescription.rec_name, - 'production': production.rec_name, - }) + raise UserError(gettext('farm_feed_production.' + 'msg_prescription_not_confirmed', + prescription=production.prescription.rec_name, + production=production.rec_name, + )) super(Production, cls).assign(productions) @classmethod @@ -317,11 +290,11 @@ class Production: for production in productions: prescription = production.prescription if prescription and prescription.state != 'draft': - cls.raise_user_error( - 'no_changes_allowed_prescription_confirmed', { - 'production': production.rec_name, - 'prescription': prescription.rec_name, - }) + raise UserError(gettext('farm_feed_production.' + 'msg_no_changes_allowed_prescription_confirmed', + production=production.rec_name, + prescription=prescription.rec_name, + )) elif prescription: production_ids_qty_uom_modified.append(production.id) @@ -341,7 +314,7 @@ class Production: prescription.save() -class Prescription: +class Prescription(metaclass=PoolMeta): __name__ = 'farm.prescription' origin_production = fields.Function(fields.Many2One('production', @@ -357,12 +330,6 @@ class Prescription: Bool(Eval('origin_production'))) field.depends.append('origin_production') - cls._error_messages.update({ - 'cant_delete_productions_prescription': ( - 'The Prescription "%(prescription)s" is related to ' - 'Production "%(production)s". You can\'t delete it.'), - }) - @classmethod def _get_origin(cls): res = super(Prescription, cls)._get_origin() @@ -400,8 +367,9 @@ class Prescription: def delete(cls, prescriptions): for prescription in prescriptions: if prescription.origin_production: - cls.raise_user_error('cant_delete_productions_prescription', { - 'prescription': prescription.rec_name, - 'production': prescription.origin_production.rec_name, - }) + raise UserError(gettext('farm_feed_production.' + 'msg_cant_delete_productions_prescription', + prescription=prescription.rec_name, + production=prescription.origin_production.rec_name, + )) super(Prescription, cls).delete(prescriptions) diff --git a/message.xml b/message.xml new file mode 100644 index 0000000..81bfd15 --- /dev/null +++ b/message.xml @@ -0,0 +1,31 @@ + + + + + The specified destination warehouse in supply request "%(request)s" is not configured as a farm for none specie. + + + The Production "%(production)s" has the Supply Request "%(origin)s" as origin which requires prescription, but it has not prescription or it isn't the origin's prescription. + + + + The Input Move "%(move)s" of Production "%(production)s" is related to a different prescription than the production. + + + + The Production "%(production)s" is related to a prescription but the next lines of this prescription doesn't appear in the Input Moves of production: %(missing_lines)s. + + + + You can't change the Quantity nor Uom of production "%(production)s" because it has the prescription "%(prescription)s" related and it is already confirmed. + + + To assign the production "%(production)s" the prescription "%(prescription)s", which is related to it, must to be Confirmed or Done. + + + The Prescription "%(prescription)s" is related to Production "%(production)s". You can\'t delete it. + + + + + diff --git a/setup.py b/setup.py index 6d1d6d6..dba5634 100644 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ from setuptools import setup import re import os -import ConfigParser +import configparser MODULE = 'farm_feed_production' PREFIX = 'nantic' @@ -14,7 +14,7 @@ MODULE2PREFIX = {} def read(fname): return open(os.path.join(os.path.dirname(__file__), fname)).read() -config = ConfigParser.ConfigParser() +config = configparser.ConfigParser() config.readfp(open('tryton.cfg')) info = dict(config.items('tryton')) for key in ('depends', 'extras_depend', 'xml'): diff --git a/tests/scenario_farm_feed_production.rst b/tests/scenario_farm_feed_production.rst index f751bb7..54710f3 100644 --- a/tests/scenario_farm_feed_production.rst +++ b/tests/scenario_farm_feed_production.rst @@ -1,41 +1,26 @@ -============================= Farm Feed Production Scenario ============================= -============= -General Setup -============= - Imports:: >>> import datetime >>> from dateutil.relativedelta import relativedelta >>> from decimal import Decimal, ROUND_HALF_EVEN >>> from proteus import config, Model, Wizard + >>> from trytond.tests.tools import activate_modules >>> from trytond.modules.company.tests.tools import create_company, \ ... get_company >>> now = datetime.datetime.now() >>> today = datetime.date.today() -Create database:: +Activate module:: - >>> config = config.set_trytond() - >>> config.pool.test = True - -Install farm_feed_production Module:: - - >>> Module = Model.get('ir.module') - >>> modules = Module.find([ - ... ('name', '=', 'farm_feed_production'), - ... ]) - >>> Module.install([x.id for x in modules], config.context) - >>> Wizard('ir.module.install_upgrade').execute('upgrade') + >>> config = activate_modules('farm_feed_production') Create company:: >>> _ = create_company() >>> company = get_company() - >>> party = company.party Reload the context:: @@ -149,7 +134,6 @@ Prepare farm and Silo locations:: ... 'parent': farm.storage_location.id, ... }], config.context) >>> location1, location2 = (Location(location1_id), Location(location2_id)) - ... config.context) >>> silo1 = Location( ... name='Silo 1', ... code='S1', @@ -202,6 +186,7 @@ Create Feed product:: ... name='Pig Feed', ... default_uom=kg, ... type='goods', + ... producible=True, ... list_price=Decimal('40'), ... cost_price=Decimal('25')) >>> feed_template.save() @@ -294,7 +279,7 @@ Create an Inventory:: >>> inventory.save() >>> Inventory.confirm([inventory.id], config.context) >>> inventory.state - u'done' + 'done' Create three individuals in location L1:: @@ -344,7 +329,7 @@ been created:: >>> supply_request.click('confirm') >>> supply_request.state - u'confirmed' + 'confirmed' >>> for line in supply_request.lines: ... line.quantity == line.move.quantity == line.production.quantity True diff --git a/tryton.cfg b/tryton.cfg index 24e151d..94aba9b 100644 --- a/tryton.cfg +++ b/tryton.cfg @@ -1,8 +1,9 @@ [tryton] -version=4.1.0 +version=5.2.0 depends: farm_prescription production_bom_versions production_supply_request xml: feed_production.xml + message.xml