Migrate to 4.2

This commit is contained in:
Sergio Morillo 2018-06-01 10:46:46 +02:00
parent 0ff1f9d329
commit 6926f0dae1
11 changed files with 47 additions and 45 deletions

View file

@ -6,8 +6,6 @@ from trytond.pool import PoolMeta, Pool
from trytond.pyson import Eval from trytond.pyson import Eval
from trytond.transaction import Transaction from trytond.transaction import Transaction
__metaclass__ = PoolMeta
__all__ = ['SaleLine'] __all__ = ['SaleLine']
@ -34,7 +32,7 @@ class SaleLine:
Sale = pool.get('sale.sale') Sale = pool.get('sale.sale')
sale = Sale.__table__() sale = Sale.__table__()
sale_line = cls.__table__() sale_line = cls.__table__()
cursor = Transaction().cursor cursor = Transaction().connection.cursor()
res = {r.id: [] for r in records} res = {r.id: [] for r in records}
for record in records: for record in records:

View file

@ -6,7 +6,7 @@ this repository contains the full copyright notices and license terms. -->
<!-- Sale line --> <!-- Sale line -->
<record model="ir.ui.view" id="sale_line_view_form"> <record model="ir.ui.view" id="sale_line_view_form">
<field name="model">sale.line</field> <field name="model">sale.line</field>
<field name="type">form</field> <field name="type" eval="None"/>
<field name="name">sale_line_form</field> <field name="name">sale_line_form</field>
<field name="inherit" ref="sale.sale_line_view_form"/> <field name="inherit" ref="sale.sale_line_view_form"/>
</record> </record>
@ -20,6 +20,5 @@ this repository contains the full copyright notices and license terms. -->
<field name="type">form</field> <field name="type">form</field>
<field name="name">sale_line_price_form</field> <field name="name">sale_line_price_form</field>
</record> </record>
</data> </data>
</tryton> </tryton>

View file

@ -31,7 +31,7 @@ class Move:
pool = Pool() pool = Pool()
Date = pool.get('ir.date') Date = pool.get('ir.date')
move = cls.__table__() move = cls.__table__()
cursor = Transaction().cursor cursor = Transaction().connection.cursor()
today = Date.today() today = Date.today()
res = {r.id: [] for r in records} res = {r.id: [] for r in records}
@ -41,25 +41,31 @@ class Move:
_shipment_name = record.shipment.__name__ _shipment_name = record.shipment.__name__
Shipment = pool.get(_shipment_name) Shipment = pool.get(_shipment_name)
shipment = Shipment.__table__() shipment = Shipment.__table__()
_party = getattr( _party = getattr(record.shipment,
record.shipment, Shipment._get_last_price_party_fieldname(), None) Shipment._get_last_price_party_fieldname(), None)
if not _party: if not _party:
continue continue
_date = (record.effective_date or record.planned_date or _date = (record.effective_date or record.planned_date or
record.shipment.effective_date or record.shipment.planned_date or today) record.shipment.effective_date or
record.shipment.planned_date or today)
cursor.execute(*shipment.join( cursor.execute(*shipment.join(
move, condition=( move, condition=(
move.shipment == Concat('%s,' % _shipment_name, shipment.id)) move.shipment == Concat('%s,' % _shipment_name,
shipment.id))
).select(Max(move.id), ).select(Max(move.id),
where=((move.product == record.product.id) & where=((move.product == record.product.id) &
(move.shipment != '%s,%s' % (_shipment_name, record.shipment.id)) & (move.shipment != '%s,%s' % (_shipment_name,
(move.state != 'cancel') & record.shipment.id)) &
(Column(shipment, Shipment._get_last_price_party_fieldname()) == _party.id) & (move.state != 'cancel') &
(Coalesce(shipment.effective_date, shipment.planned_date) <= _date)), (Column(shipment,
order_by=(move.product, shipment.id), Shipment._get_last_price_party_fieldname()) ==
group_by=(move.product, shipment.id), _party.id) &
limit=3) (Coalesce(shipment.effective_date,
shipment.planned_date) <= _date)),
order_by=(move.product, shipment.id),
group_by=(move.product, shipment.id),
limit=3)
) )
res[record.id] = [row[0] for row in cursor.fetchall()] or [] res[record.id] = [row[0] for row in cursor.fetchall()] or []
return res return res
@ -78,12 +84,13 @@ class ShipmentLastPriceMixin(object):
move = Move.__table__() move = Move.__table__()
active_move = Move.__table__() active_move = Move.__table__()
shipment = cls.__table__() shipment = cls.__table__()
cursor = Transaction().cursor cursor = Transaction().connection.cursor()
res = {r.id: [] for r in records} res = {r.id: [] for r in records}
for record in records: for record in records:
_products = set([m.product.id for m in record.outgoing_moves]) _products = set([m.product.id for m in record.outgoing_moves])
party = getattr(record, cls._get_last_price_party_fieldname(), None) party = getattr(record,
cls._get_last_price_party_fieldname(), None)
if not party or not _products: if not party or not _products:
continue continue
cursor.execute(*shipment.join(move, condition=( cursor.execute(*shipment.join(move, condition=(
@ -91,17 +98,20 @@ class ShipmentLastPriceMixin(object):
).join(active_move, condition=( ).join(active_move, condition=(
active_move.product == move.product) active_move.product == move.product)
).select(Max(move.id), ).select(Max(move.id),
where=((active_move.shipment == Concat('%s,' % cls.__name__, record.id)) & where=((active_move.shipment ==
(shipment.id != record.id) & Concat('%s,' % cls.__name__, record.id)) &
(shipment.state != 'cancel') & (shipment.id != record.id) &
(Column(shipment, cls._get_last_price_party_fieldname()) == party.id) & (shipment.state != 'cancel') &
(Coalesce(shipment.effective_date, (Column(shipment,
shipment.planned_date) <= Coalesce( cls._get_last_price_party_fieldname()) ==
record.effective_date, party.id) &
record.planned_date))), (Coalesce(shipment.effective_date,
order_by=(move.product, shipment.id), shipment.planned_date) <= Coalesce(
group_by=(move.product, shipment.id), record.effective_date,
limit=len(_products) * 3) record.planned_date))),
order_by=(move.product, shipment.id),
group_by=(move.product, shipment.id),
limit=len(_products) * 3)
) )
res[record.id] = [row[0] for row in cursor.fetchall()] or [] res[record.id] = [row[0] for row in cursor.fetchall()] or []
return res return res

View file

@ -6,7 +6,7 @@ this repository contains the full copyright notices and license terms. -->
<!-- Stock move --> <!-- Stock move -->
<record model="ir.ui.view" id="stock_move_view_form"> <record model="ir.ui.view" id="stock_move_view_form">
<field name="model">stock.move</field> <field name="model">stock.move</field>
<field name="type">form</field> <field name="type" eval="None"/>
<field name="name">stock_move_form</field> <field name="name">stock_move_form</field>
<field name="inherit" ref="stock.move_view_form"/> <field name="inherit" ref="stock.move_view_form"/>
</record> </record>
@ -24,7 +24,7 @@ this repository contains the full copyright notices and license terms. -->
<!-- Shipment out --> <!-- Shipment out -->
<record model="ir.ui.view" id="shipment_out_view_form"> <record model="ir.ui.view" id="shipment_out_view_form">
<field name="model">stock.shipment.out</field> <field name="model">stock.shipment.out</field>
<field name="type">form</field> <field name="type" eval="None"/>
<field name="name">shipment_out_form</field> <field name="name">shipment_out_form</field>
<field name="inherit" ref="stock.shipment_out_view_form"/> <field name="inherit" ref="stock.shipment_out_view_form"/>
</record> </record>

View file

@ -5,6 +5,7 @@ Stock Last Price Scenario
Imports:: Imports::
>>> import datetime >>> import datetime
>>> from trytond.tests.tools import activate_modules
>>> from dateutil.relativedelta import relativedelta >>> from dateutil.relativedelta import relativedelta
>>> from decimal import Decimal >>> from decimal import Decimal
>>> from proteus import config, Model, Wizard >>> from proteus import config, Model, Wizard
@ -20,13 +21,7 @@ Create a database::
Install stock_last_price:: Install stock_last_price::
>>> Module = Model.get('ir.module') >>> config = activate_modules('stock_last_price')
>>> module, = Module.find([
... ('name', '=', 'stock_last_price'),
... ])
>>> module.click('install')
>>> Wizard('ir.module.install_upgrade').execute('upgrade')
Create company:: Create company::

View file

@ -1,5 +1,5 @@
[tryton] [tryton]
version=3.8.0 version=4.2.0
depends: depends:
ir ir
res res

View file

@ -1,7 +1,7 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<!-- The COPYRIGHT file at the top level of this repository contains the full <!-- The COPYRIGHT file at the top level of this repository contains the full
copyright notices and license terms. --> copyright notices and license terms. -->
<form string="Last sale prices"> <form>
<label name="sale"/> <label name="sale"/>
<field name="sale"/> <field name="sale"/>
<label name="product"/> <label name="product"/>

View file

@ -1,7 +1,7 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<!-- The COPYRIGHT file at the top level of this repository contains the full <!-- The COPYRIGHT file at the top level of this repository contains the full
copyright notices and license terms. --> copyright notices and license terms. -->
<tree string="Last sale prices"> <tree>
<field name="sale"/> <field name="sale"/>
<field name="sale_date"/> <field name="sale_date"/>
<field name="product"/> <field name="product"/>

View file

@ -1,7 +1,7 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<!-- The COPYRIGHT file at the top level of this repository contains the full <!-- The COPYRIGHT file at the top level of this repository contains the full
copyright notices and license terms. --> copyright notices and license terms. -->
<form string="Last move prices"> <form>
<label name="shipment"/> <label name="shipment"/>
<field name="shipment"/> <field name="shipment"/>
<label name="product"/> <label name="product"/>

View file

@ -1,7 +1,7 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<!-- The COPYRIGHT file at the top level of this repository contains the full <!-- The COPYRIGHT file at the top level of this repository contains the full
copyright notices and license terms. --> copyright notices and license terms. -->
<tree string="Last move prices"> <tree>
<field name="shipment"/> <field name="shipment"/>
<field name="effective_date"/> <field name="effective_date"/>
<field name="product"/> <field name="product"/>