changeset bc9a167e048c in modules/stock_lot:default
details: https://hg.tryton.org/modules/stock_lot?cmd=changeset;node=bc9a167e048c
description:
Add relates for lots
- relate from lot to locations quantity
- relate from product/template to lots by warehouse
issue9504
review298351002
diffstat:
CHANGELOG | 3 +
__init__.py | 2 +
stock.py | 46 ++++++++++++++++++++
stock.xml | 75 ++++++++++++++++++++++++++++++++++
view/lot_by_warehouse_context_form.xml | 12 +++++
5 files changed, 138 insertions(+), 0 deletions(-)
diffs (179 lines):
diff -r 234ea81bce99 -r bc9a167e048c CHANGELOG
--- a/CHANGELOG Sat Oct 03 23:47:40 2020 +0200
+++ b/CHANGELOG Sun Oct 11 16:05:16 2020 +0200
@@ -1,3 +1,6 @@
+* Add relate to locations quantity
+* Add lots by warehouse relate
+
Version 5.6.0 - 2020-05-04
* Bug fixes (see mercurial logs for details)
diff -r 234ea81bce99 -r bc9a167e048c __init__.py
--- a/__init__.py Sat Oct 03 23:47:40 2020 +0200
+++ b/__init__.py Sun Oct 11 16:05:16 2020 +0200
@@ -10,6 +10,8 @@
Pool.register(
stock.Lot,
stock.LotByLocationContext,
+ stock.LotByWarehouseContext,
+ stock.Location,
stock.Move,
stock.ShipmentIn,
stock.ShipmentOut,
diff -r 234ea81bce99 -r bc9a167e048c stock.py
--- a/stock.py Sat Oct 03 23:47:40 2020 +0200
+++ b/stock.py Sun Oct 11 16:05:16 2020 +0200
@@ -105,6 +105,52 @@
return self.forecast_date
+class LotByWarehouseContext(LotByLocationContext):
+ "Lot by Warehouse"
+ __name__ = 'stock.lots_by_warehouse.context'
+ warehouse = fields.Many2One(
+ 'stock.location', "Warehouse", required=True,
+ domain=[
+ ('type', '=', 'warehouse'),
+ ],
+ )
+ locations = fields.Function(
+ fields.Many2Many('stock.location', None, None, "Locations"),
+ 'on_change_with_locations')
+
+ @classmethod
+ def default_warehouse(cls):
+ return Pool().get('stock.location').get_default_warehouse()
+
+ @fields.depends('warehouse')
+ def on_change_with_locations(self, name=None):
+ locations = []
+ if self.warehouse:
+ locations.append(self.warehouse.id)
+ return locations
+
+
+class Location(metaclass=PoolMeta):
+ __name__ = 'stock.location'
+
+ @classmethod
+ def _get_quantity_grouping(cls):
+ pool = Pool()
+ Lot = pool.get('stock.lot')
+ context = Transaction().context
+ grouping, grouping_filter, key = super()._get_quantity_grouping()
+ if context.get('lot') is not None:
+ try:
+ lot, = Lot.search([('id', '=', context['lot'])])
+ except ValueError:
+ pass
+ else:
+ grouping = ('product', 'lot',)
+ grouping_filter = ([lot.product.id], [lot.id])
+ key = (lot.product.id, lot.id)
+ return grouping, grouping_filter, key
+
+
class Move(metaclass=PoolMeta):
__name__ = 'stock.move'
lot = fields.Many2One('stock.lot', 'Lot',
diff -r 234ea81bce99 -r bc9a167e048c stock.xml
--- a/stock.xml Sat Oct 03 23:47:40 2020 +0200
+++ b/stock.xml Sun Oct 11 16:05:16 2020 +0200
@@ -95,6 +95,81 @@
<field name="action" ref="act_lots_by_locations"/>
</record>
+ <record model="ir.ui.view" id="lots_by_warehouse_context_view_form">
+ <field name="model">stock.lots_by_warehouse.context</field>
+ <field name="inherit" ref="lots_by_location_context_view_form"/>
+ <field name="name">lot_by_warehouse_context_form</field>
+ </record>
+
+ <record model="ir.action.act_window" id="act_lots_by_warehouse">
+ <field name="name">Lots By Warehouse</field>
+ <field name="res_model">stock.lot</field>
+ <field
+ name="domain"
+ eval="[If(Eval('active_ids', []) == [Eval('active_id')],
(If(Eval('active_model') == 'product.template', 'product.template', 'product'),
'=', Eval('active_id', -1)), (If(Eval('active_model') == 'product.template',
'product.template', 'product'), 'in', Eval('active_ids', []))), ['OR',
('quantity', '!=', 0.0), ('forecast_quantity', '!=', 0.0)]]"
+ pyson="1"/>
+ <field name="search_value"
+ eval="None" />
+ <field name="context_model">stock.lots_by_warehouse.context</field>
+ </record>
+ <record model="ir.action.act_window.view"
id="act_lots_by_warehouse_view1">
+ <field name="sequence" eval="10"/>
+ <field name="view" ref="lot_quantity_view_tree"/>
+ <field name="act_window" ref="act_lots_by_warehouse"/>
+ </record>
+ <record model="ir.action.keyword" id="act_lots_by_warehouse_keyword1">
+ <field name="keyword">form_relate</field>
+ <field name="model">product.template,-1</field>
+ <field name="action" ref="act_lots_by_warehouse"/>
+ </record>
+ <record model="ir.action.keyword" id="act_lots_by_warehouse_keyword2">
+ <field name="keyword">form_relate</field>
+ <field name="model">product.product,-1</field>
+ <field name="action" ref="act_lots_by_warehouse"/>
+ </record>
+
+ <record model="ir.action.act_window" id="act_location_quantity_tree">
+ <field name="name">Locations Tree Quantity</field>
+ <field name="res_model">stock.location</field>
+ <field name="domain" eval="[('parent', '=', None)]" pyson="1"/>
+ <field
+ name="context"
+ eval="{'lot': Eval('active_id'), 'stock_skip_warehouse':
False}"
+ pyson="1"/>
+ <field name="context_model">stock.lots_by_location.context</field>
+ </record>
+ <record model="ir.action.act_window.view"
id="act_location_quantity_tree_view1">
+ <field name="sequence" eval="10"/>
+ <field name="view" ref="stock.location_quantity_view_tree"/>
+ <field name="act_window" ref="act_location_quantity_tree"/>
+ </record>
+ <record model="ir.action.keyword"
id="act_location_quantity_tree_keyword1">
+ <field name="keyword">form_relate</field>
+ <field name="model">stock.lot,-1</field>
+ <field name="action" ref="act_location_quantity_tree"/>
+ </record>
+
+ <record model="ir.action.act_window" id="act_location_quantity_list">
+ <field name="name">Locations List Quantity</field>
+ <field name="res_model">stock.location</field>
+ <field name="search_value" eval="['OR', ('quantity', '!=', 0),
('forecast_quantity', '!=', 0)]" pyson="1"/>
+ <field
+ name="context"
+ eval="{'lot': Eval('active_id'), 'with_childs': False,
'stock_skip_warehouse': False}"
+ pyson="1"/>
+ <field name="context_model">stock.lots_by_location.context</field>
+ </record>
+ <record model="ir.action.act_window.view"
id="act_location_quantity_list_view">
+ <field name="sequence" eval="10"/>
+ <field name="view" ref="stock.location_quantity_view_list"/>
+ <field name="act_window" ref="act_location_quantity_list"/>
+ </record>
+ <record model="ir.action.keyword"
id="act_location_quantity_list_keyword1">
+ <field name="keyword">form_relate</field>
+ <field name="model">stock.lot,-1</field>
+ <field name="action" ref="act_location_quantity_list"/>
+ </record>
+
<record model="ir.action.act_window" id="act_move_form_relate_lot">
<field name="name">Moves</field>
<field name="res_model">stock.move</field>
diff -r 234ea81bce99 -r bc9a167e048c view/lot_by_warehouse_context_form.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/view/lot_by_warehouse_context_form.xml Sun Oct 11 16:05:16 2020 +0200
@@ -0,0 +1,12 @@
+<?xml version="1.0"?>
+<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
+this repository contains the full copyright notices and license terms. -->
+<data>
+ <xpath expr="//label[@name='forecast_date']" position="before">
+ <label name="warehouse"/>
+ <field name="warehouse"/>
+ </xpath>
+ <xpath expr="//field[@name='stock_date_end']" position="before">
+ <field name="locations" invisible="1" colspan="4"/>
+ </xpath>
+</data>