lims: add Many2Many field to stock.location model and a function Many2Many to stock.shipment.internal model, to modify the domain of to_location field on stock.shipment.internal model

This commit is contained in:
Francisco Moyano 2021-07-01 19:47:37 -03:00 committed by Adrián Bernardi
parent cec51c8343
commit c0d455c732
5 changed files with 54 additions and 1 deletions

View File

@ -221,6 +221,7 @@ def register():
stock.Location,
stock.Move,
stock.ShipmentInternal,
stock.LocationShipmentInternalRestrictionLocation,
uom.Uom,
uom.UomCategory,
uom.Template,

View File

@ -3,7 +3,7 @@
# The COPYRIGHT file at the top level of this repository contains
# the full copyright notices and license terms.
from trytond.model import fields
from trytond.model import fields, ModelSQL
from trytond.pyson import In, Eval, Bool, If
from trytond.pool import Pool, PoolMeta
from trytond.transaction import Transaction
@ -13,6 +13,10 @@ class Location(metaclass=PoolMeta):
__name__ = 'stock.location'
storage_time = fields.Integer('Storage time (in months)')
internal_shipment_to_location_restrictions =\
fields.Many2Many('stock.location-stock.location',
'from_location','to_location',
'Internal Shipment To Location Restrictions')
@classmethod
def search_rec_name(cls, name, clause):
@ -77,6 +81,16 @@ class Move(metaclass=PoolMeta):
class ShipmentInternal(metaclass=PoolMeta):
__name__ = 'stock.shipment.internal'
to_location_domain = fields.Function(fields.Many2Many(
'stock.location',None, None,
'Internal Shipment To Location Restrictions'), 'on_change_with_to_location_domain')
@fields.depends('from_location')
def on_change_with_to_location_domain(self, name=None):
if self.from_location and self.from_location.internal_shipment_to_location_restrictions:
return [x.id for x in self.from_location.internal_shipment_to_location_restrictions]
return []
@classmethod
def copy(cls, shipments, default=None):
with Transaction().set_context(check_current_location=False):
@ -126,3 +140,24 @@ class ShipmentInternal(metaclass=PoolMeta):
def assign_force(cls, shipments):
with Transaction().set_context(check_current_location=False):
super().assign_force(shipments)
@classmethod
def __setup__(cls):
super().__setup__()
cls.to_location.domain = [
[('type', 'in', ['view', 'storage', 'lost_found'])],
[If(Eval('to_location_domain'),
('id','in',Eval('to_location_domain')),
('id','>',0))]]
class LocationShipmentInternalRestrictionLocation(ModelSQL):
'Location restriction'
__name__ = 'stock.location-stock.location'
from_location =\
fields.Many2One('stock.location', 'Input location',
required=True, ondelete='CASCADE')
to_location =\
fields.Many2One('stock.location', 'Output location',
required=True, ondelete='CASCADE')

View File

@ -36,6 +36,12 @@
<field name="name">stock_shipment_in_form</field>
</record>
<record model="ir.ui.view" id="lims_shipment_internal_view_form">
<field name="model">stock.shipment.internal</field>
<field name="inherit" ref="stock.shipment_internal_view_form"/>
<field name="name">stock_shipment_internal_form</field>
</record>
<!-- Fraction Product -->
<record model="product.template" id="template_fraction">

View File

@ -6,4 +6,7 @@
<field name="storage_time"/>
</group>
</xpath>
<xpath expr="/form/field[@name='childs']" position="after">
<field name="internal_shipment_to_location_restrictions"/>
</xpath>
</data>

View File

@ -0,0 +1,8 @@
<?xml version="1.0"?>
<data>
<xpath expr="/form/group[@id='buttons']" position="after">
<group id="invisible_group" colspan="4">
<field name="to_location_domain" invisible="1"/>
</group>
</xpath>
</data>