mirror of
https://gitlab.com/datalifeit/trytond-stock_last_price
synced 2023-12-14 04:52:59 +01:00
Migrate to 4.2
This commit is contained in:
parent
0ff1f9d329
commit
6926f0dae1
11 changed files with 47 additions and 45 deletions
4
sale.py
4
sale.py
|
@ -6,8 +6,6 @@ from trytond.pool import PoolMeta, Pool
|
|||
from trytond.pyson import Eval
|
||||
from trytond.transaction import Transaction
|
||||
|
||||
__metaclass__ = PoolMeta
|
||||
|
||||
__all__ = ['SaleLine']
|
||||
|
||||
|
||||
|
@ -34,7 +32,7 @@ class SaleLine:
|
|||
Sale = pool.get('sale.sale')
|
||||
sale = Sale.__table__()
|
||||
sale_line = cls.__table__()
|
||||
cursor = Transaction().cursor
|
||||
cursor = Transaction().connection.cursor()
|
||||
|
||||
res = {r.id: [] for r in records}
|
||||
for record in records:
|
||||
|
|
3
sale.xml
3
sale.xml
|
@ -6,7 +6,7 @@ this repository contains the full copyright notices and license terms. -->
|
|||
<!-- Sale line -->
|
||||
<record model="ir.ui.view" id="sale_line_view_form">
|
||||
<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="inherit" ref="sale.sale_line_view_form"/>
|
||||
</record>
|
||||
|
@ -20,6 +20,5 @@ this repository contains the full copyright notices and license terms. -->
|
|||
<field name="type">form</field>
|
||||
<field name="name">sale_line_price_form</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</tryton>
|
34
stock.py
34
stock.py
|
@ -31,7 +31,7 @@ class Move:
|
|||
pool = Pool()
|
||||
Date = pool.get('ir.date')
|
||||
move = cls.__table__()
|
||||
cursor = Transaction().cursor
|
||||
cursor = Transaction().connection.cursor()
|
||||
|
||||
today = Date.today()
|
||||
res = {r.id: [] for r in records}
|
||||
|
@ -41,22 +41,28 @@ class Move:
|
|||
_shipment_name = record.shipment.__name__
|
||||
Shipment = pool.get(_shipment_name)
|
||||
shipment = Shipment.__table__()
|
||||
_party = getattr(
|
||||
record.shipment, Shipment._get_last_price_party_fieldname(), None)
|
||||
_party = getattr(record.shipment,
|
||||
Shipment._get_last_price_party_fieldname(), None)
|
||||
if not _party:
|
||||
continue
|
||||
|
||||
_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(
|
||||
move, condition=(
|
||||
move.shipment == Concat('%s,' % _shipment_name, shipment.id))
|
||||
move.shipment == Concat('%s,' % _shipment_name,
|
||||
shipment.id))
|
||||
).select(Max(move.id),
|
||||
where=((move.product == record.product.id) &
|
||||
(move.shipment != '%s,%s' % (_shipment_name, record.shipment.id)) &
|
||||
(move.shipment != '%s,%s' % (_shipment_name,
|
||||
record.shipment.id)) &
|
||||
(move.state != 'cancel') &
|
||||
(Column(shipment, Shipment._get_last_price_party_fieldname()) == _party.id) &
|
||||
(Coalesce(shipment.effective_date, shipment.planned_date) <= _date)),
|
||||
(Column(shipment,
|
||||
Shipment._get_last_price_party_fieldname()) ==
|
||||
_party.id) &
|
||||
(Coalesce(shipment.effective_date,
|
||||
shipment.planned_date) <= _date)),
|
||||
order_by=(move.product, shipment.id),
|
||||
group_by=(move.product, shipment.id),
|
||||
limit=3)
|
||||
|
@ -78,12 +84,13 @@ class ShipmentLastPriceMixin(object):
|
|||
move = Move.__table__()
|
||||
active_move = Move.__table__()
|
||||
shipment = cls.__table__()
|
||||
cursor = Transaction().cursor
|
||||
cursor = Transaction().connection.cursor()
|
||||
|
||||
res = {r.id: [] for r in records}
|
||||
for record in records:
|
||||
_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:
|
||||
continue
|
||||
cursor.execute(*shipment.join(move, condition=(
|
||||
|
@ -91,10 +98,13 @@ class ShipmentLastPriceMixin(object):
|
|||
).join(active_move, condition=(
|
||||
active_move.product == move.product)
|
||||
).select(Max(move.id),
|
||||
where=((active_move.shipment == Concat('%s,' % cls.__name__, record.id)) &
|
||||
where=((active_move.shipment ==
|
||||
Concat('%s,' % cls.__name__, record.id)) &
|
||||
(shipment.id != record.id) &
|
||||
(shipment.state != 'cancel') &
|
||||
(Column(shipment, cls._get_last_price_party_fieldname()) == party.id) &
|
||||
(Column(shipment,
|
||||
cls._get_last_price_party_fieldname()) ==
|
||||
party.id) &
|
||||
(Coalesce(shipment.effective_date,
|
||||
shipment.planned_date) <= Coalesce(
|
||||
record.effective_date,
|
||||
|
|
|
@ -6,7 +6,7 @@ this repository contains the full copyright notices and license terms. -->
|
|||
<!-- Stock move -->
|
||||
<record model="ir.ui.view" id="stock_move_view_form">
|
||||
<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="inherit" ref="stock.move_view_form"/>
|
||||
</record>
|
||||
|
@ -24,7 +24,7 @@ this repository contains the full copyright notices and license terms. -->
|
|||
<!-- Shipment out -->
|
||||
<record model="ir.ui.view" id="shipment_out_view_form">
|
||||
<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="inherit" ref="stock.shipment_out_view_form"/>
|
||||
</record>
|
||||
|
|
|
@ -5,6 +5,7 @@ Stock Last Price Scenario
|
|||
Imports::
|
||||
|
||||
>>> import datetime
|
||||
>>> from trytond.tests.tools import activate_modules
|
||||
>>> from dateutil.relativedelta import relativedelta
|
||||
>>> from decimal import Decimal
|
||||
>>> from proteus import config, Model, Wizard
|
||||
|
@ -20,13 +21,7 @@ Create a database::
|
|||
|
||||
Install stock_last_price::
|
||||
|
||||
>>> Module = Model.get('ir.module')
|
||||
>>> module, = Module.find([
|
||||
... ('name', '=', 'stock_last_price'),
|
||||
... ])
|
||||
>>> module.click('install')
|
||||
>>> Wizard('ir.module.install_upgrade').execute('upgrade')
|
||||
|
||||
>>> config = activate_modules('stock_last_price')
|
||||
|
||||
Create company::
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
[tryton]
|
||||
version=3.8.0
|
||||
version=4.2.0
|
||||
depends:
|
||||
ir
|
||||
res
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0"?>
|
||||
<!-- The COPYRIGHT file at the top level of this repository contains the full
|
||||
copyright notices and license terms. -->
|
||||
<form string="Last sale prices">
|
||||
<form>
|
||||
<label name="sale"/>
|
||||
<field name="sale"/>
|
||||
<label name="product"/>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0"?>
|
||||
<!-- The COPYRIGHT file at the top level of this repository contains the full
|
||||
copyright notices and license terms. -->
|
||||
<tree string="Last sale prices">
|
||||
<tree>
|
||||
<field name="sale"/>
|
||||
<field name="sale_date"/>
|
||||
<field name="product"/>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0"?>
|
||||
<!-- The COPYRIGHT file at the top level of this repository contains the full
|
||||
copyright notices and license terms. -->
|
||||
<form string="Last move prices">
|
||||
<form>
|
||||
<label name="shipment"/>
|
||||
<field name="shipment"/>
|
||||
<label name="product"/>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0"?>
|
||||
<!-- The COPYRIGHT file at the top level of this repository contains the full
|
||||
copyright notices and license terms. -->
|
||||
<tree string="Last move prices">
|
||||
<tree>
|
||||
<field name="shipment"/>
|
||||
<field name="effective_date"/>
|
||||
<field name="product"/>
|
||||
|
|
Loading…
Reference in a new issue