Adapt to Tryton 5.2

This commit is contained in:
Albert Cervera i Areny 2019-06-15 02:01:30 +02:00
parent 7dc09be3ed
commit fd4259f636
6 changed files with 85 additions and 100 deletions

View file

@ -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')

View file

@ -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)

31
message.xml Normal file
View file

@ -0,0 +1,31 @@
<?xml version="1.0"?>
<tryton>
<data group="1">
<record model="ir.message" id="msg_to_warehouse_farm_line_not_available">
<field name="text">The specified destination warehouse in supply request "%(request)s" is not configured as a farm for none specie.</field>
</record>
<record model="ir.message" id="msg_from_supply_request_invalid_prescription">
<field name="text">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.
</field>
</record>
<record model="ir.message" id="msg_invalid_input_move_prescription">
<field name="text">The Input Move "%(move)s" of Production "%(production)s" is related to a different prescription than the production.
</field>
</record>
<record model="ir.message" id="msg_missing_iniput-Moves_from_prescription">
<field name="text">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.
</field>
</record>
<record model="ir.message" id="msg_no_changes_allowed_prescription_confirmed">
<field name="text">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.</field>
</record>
<record model="ir.message" id="msg_prescription_not_confirmed">
<field name="text">To assign the production "%(production)s" the prescription "%(prescription)s", which is related to it, must to be Confirmed or Done.</field>
</record>
<record model="ir.message" id="msg_cant_delete_productions_prescription">
<field name="text">The Prescription "%(prescription)s" is related to Production "%(production)s". You can\'t delete it.</field>
</record>
</data>
</tryton>

View file

@ -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'):

View file

@ -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

View file

@ -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