From 660e714983003c829a8b580a189ec4658cfe6583 Mon Sep 17 00:00:00 2001 From: laurentbarontini Date: Fri, 16 Jan 2026 21:07:56 +0100 Subject: [PATCH] 16.01.26 --- modules/purchase/purchase.py | 33 +++++++++++++-------------- modules/purchase_trade/__init__.py | 1 + modules/purchase_trade/dashboard.py | 2 +- modules/purchase_trade/lot.py | 4 ++++ modules/purchase_trade/stock.py | 35 ++++++++++++++++++++--------- 5 files changed, 46 insertions(+), 29 deletions(-) diff --git a/modules/purchase/purchase.py b/modules/purchase/purchase.py index c197555..078bd72 100755 --- a/modules/purchase/purchase.py +++ b/modules/purchase/purchase.py @@ -1990,8 +1990,7 @@ class Line(sequence_ordered(), ModelSQL, ModelView): ''' pool = Pool() Move = pool.get('stock.move') - InvoiceLine = pool.get('account.invoice.line') - Uom = pool.get('product.uom') + Location = pool.get('stock.location') if self.type != 'line': return if not self.product: @@ -2049,24 +2048,24 @@ class Line(sequence_ordered(), ModelSQL, ModelView): move.from_location = from_location if to_location.type != 'customer': - move.to_location = 8 + move.to_location = Location.get_transit_id() else: move.to_location = to_location unit_price = l.get_lot_price() - if l.invoice_line_prov != None : - prov_inv = InvoiceLine(l.invoice_line_prov) - quantity -= prov_inv.quantity - if quantity < 0 : - move.from_location = self.purchase.to_location - move.to_location = 16 - elif quantity > 0 : - move.from_location = 16 - move.to_location = self.purchase.to_location - quantity = abs(quantity) - unit_price = prov_inv.unit_price - if quantity == 0: - continue + # if l.invoice_line_prov != None : + # prov_inv = InvoiceLine(l.invoice_line_prov) + # quantity -= prov_inv.quantity + # if quantity < 0 : + # move.from_location = self.purchase.to_location + # move.to_location = 16 + # elif quantity > 0 : + # move.from_location = 16 + # move.to_location = self.purchase.to_location + # quantity = abs(quantity) + # unit_price = prov_inv.unit_price + # if quantity == 0: + # continue move.quantity = quantity move.unit = self.unit move.product = l.lot_product @@ -2086,7 +2085,7 @@ class Line(sequence_ordered(), ModelSQL, ModelView): moves.append(move) if move.to_location.type != 'customer': move_to, = Move.copy([move.id], default={ - 'from_location': 8, + 'from_location': Location.get_transit_id(), 'to_location': to_location, }) moves.append(move_to) diff --git a/modules/purchase_trade/__init__.py b/modules/purchase_trade/__init__.py index 3a496c5..7407785 100755 --- a/modules/purchase_trade/__init__.py +++ b/modules/purchase_trade/__init__.py @@ -112,6 +112,7 @@ def register(): forex.ForexBI, purchase.PnlBI, stock.Move, + stock.Location, stock.InvoiceLine, stock.ShipmentIn, stock.ShipmentInternal, diff --git a/modules/purchase_trade/dashboard.py b/modules/purchase_trade/dashboard.py index d01aec7..d79bd81 100755 --- a/modules/purchase_trade/dashboard.py +++ b/modules/purchase_trade/dashboard.py @@ -1,5 +1,5 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of -# this repository contains the full copyright notices and license terms. +# this repository contains the full copyright notices and license terms. from trytond.model import ModelSQL, ModelView, fields, sequence_ordered, ModelSingleton from trytond.pyson import Eval from trytond.transaction import Transaction diff --git a/modules/purchase_trade/lot.py b/modules/purchase_trade/lot.py index 3d5a2c1..5995b6c 100755 --- a/modules/purchase_trade/lot.py +++ b/modules/purchase_trade/lot.py @@ -2031,6 +2031,10 @@ class LotShipping(Wizard): move = Move(l.move) move.shipment = shipment_origin Move.save([move]) + linked_transit_move = move.get_linked_transit_move() + if linked_transit_move: + linked_transit_move.shipment = shipment_origin + Move.save([linked_transit_move]) #Decrease forecasted virtual part shipped vlot_p = l.getVlot_p() l.updateVirtualPart(-l.get_current_quantity_converted(),shipment_origin,l.getVlot_s()) diff --git a/modules/purchase_trade/stock.py b/modules/purchase_trade/stock.py index 5e76ced..6183c3a 100755 --- a/modules/purchase_trade/stock.py +++ b/modules/purchase_trade/stock.py @@ -20,6 +20,24 @@ from collections import defaultdict import logging logger = logging.getLogger(__name__) +class Location(metaclass=PoolMeta): + __name__ = 'stock.location' + + @classmethod + def get_transit_id(cls): + transit = cls.search([('name', '=', 'Transit')], limit=1) + if transit: + return transit[0].id + else: + transit = cls() + transit.name = 'Transit' + transit.type = 'storage' + cls.save([transit]) + return transit.id + + def is_transit(self): + if self.name == 'Transit': + return True class Move(metaclass=PoolMeta): __name__ = 'stock.move' @@ -28,17 +46,12 @@ class Move(metaclass=PoolMeta): lotqt = fields.One2Many('lot.qt','lot_move',"Lots") lot = fields.Many2One('lot.lot',"Lot") - # @fields.depends('lotqt','unit') - # def on_change_with_quantity(self): - # if self.lotqt: - # pool = Pool() - # Uom = pool.get('product.uom') - # if self.unit: - # return round(sum([(e.lot_quantity if e.lot_quantity else 0) for e in self.lotqt]),2) - # else: - # return 0 - # else: - # return 0 + def get_linked_transit_move(self): + if self.from_location.is_transit(): + Move = Pool().get('stock.move') + Location = Pool().get('stock.location') + moves = Move.search([('lot','=',self.lot),('to_location','=',Location.get_transit_id())],order=[('id', 'DESC')],limit=1) + return moves[0] if moves else None @classmethod def validate(cls, moves):