dev #5

Merged
admin merged 5 commits from dev into main 2026-01-17 05:48:04 +00:00
5 changed files with 46 additions and 29 deletions

View File

@@ -1990,8 +1990,7 @@ class Line(sequence_ordered(), ModelSQL, ModelView):
''' '''
pool = Pool() pool = Pool()
Move = pool.get('stock.move') Move = pool.get('stock.move')
InvoiceLine = pool.get('account.invoice.line') Location = pool.get('stock.location')
Uom = pool.get('product.uom')
if self.type != 'line': if self.type != 'line':
return return
if not self.product: if not self.product:
@@ -2049,24 +2048,24 @@ class Line(sequence_ordered(), ModelSQL, ModelView):
move.from_location = from_location move.from_location = from_location
if to_location.type != 'customer': if to_location.type != 'customer':
move.to_location = 8 move.to_location = Location.get_transit_id()
else: else:
move.to_location = to_location move.to_location = to_location
unit_price = l.get_lot_price() unit_price = l.get_lot_price()
if l.invoice_line_prov != None : # if l.invoice_line_prov != None :
prov_inv = InvoiceLine(l.invoice_line_prov) # prov_inv = InvoiceLine(l.invoice_line_prov)
quantity -= prov_inv.quantity # quantity -= prov_inv.quantity
if quantity < 0 : # if quantity < 0 :
move.from_location = self.purchase.to_location # move.from_location = self.purchase.to_location
move.to_location = 16 # move.to_location = 16
elif quantity > 0 : # elif quantity > 0 :
move.from_location = 16 # move.from_location = 16
move.to_location = self.purchase.to_location # move.to_location = self.purchase.to_location
quantity = abs(quantity) # quantity = abs(quantity)
unit_price = prov_inv.unit_price # unit_price = prov_inv.unit_price
if quantity == 0: # if quantity == 0:
continue # continue
move.quantity = quantity move.quantity = quantity
move.unit = self.unit move.unit = self.unit
move.product = l.lot_product move.product = l.lot_product
@@ -2086,7 +2085,7 @@ class Line(sequence_ordered(), ModelSQL, ModelView):
moves.append(move) moves.append(move)
if move.to_location.type != 'customer': if move.to_location.type != 'customer':
move_to, = Move.copy([move.id], default={ move_to, = Move.copy([move.id], default={
'from_location': 8, 'from_location': Location.get_transit_id(),
'to_location': to_location, 'to_location': to_location,
}) })
moves.append(move_to) moves.append(move_to)

View File

@@ -112,6 +112,7 @@ def register():
forex.ForexBI, forex.ForexBI,
purchase.PnlBI, purchase.PnlBI,
stock.Move, stock.Move,
stock.Location,
stock.InvoiceLine, stock.InvoiceLine,
stock.ShipmentIn, stock.ShipmentIn,
stock.ShipmentInternal, stock.ShipmentInternal,

View File

@@ -1,5 +1,5 @@
# This file is part of Tryton. The COPYRIGHT file at the top level of # 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.model import ModelSQL, ModelView, fields, sequence_ordered, ModelSingleton
from trytond.pyson import Eval from trytond.pyson import Eval
from trytond.transaction import Transaction from trytond.transaction import Transaction

View File

@@ -2031,6 +2031,10 @@ class LotShipping(Wizard):
move = Move(l.move) move = Move(l.move)
move.shipment = shipment_origin move.shipment = shipment_origin
Move.save([move]) 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 #Decrease forecasted virtual part shipped
vlot_p = l.getVlot_p() vlot_p = l.getVlot_p()
l.updateVirtualPart(-l.get_current_quantity_converted(),shipment_origin,l.getVlot_s()) l.updateVirtualPart(-l.get_current_quantity_converted(),shipment_origin,l.getVlot_s())

View File

@@ -20,6 +20,24 @@ from collections import defaultdict
import logging import logging
logger = logging.getLogger(__name__) 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): class Move(metaclass=PoolMeta):
__name__ = 'stock.move' __name__ = 'stock.move'
@@ -28,17 +46,12 @@ class Move(metaclass=PoolMeta):
lotqt = fields.One2Many('lot.qt','lot_move',"Lots") lotqt = fields.One2Many('lot.qt','lot_move',"Lots")
lot = fields.Many2One('lot.lot',"Lot") lot = fields.Many2One('lot.lot',"Lot")
# @fields.depends('lotqt','unit') def get_linked_transit_move(self):
# def on_change_with_quantity(self): if self.from_location.is_transit():
# if self.lotqt: Move = Pool().get('stock.move')
# pool = Pool() Location = Pool().get('stock.location')
# Uom = pool.get('product.uom') moves = Move.search([('lot','=',self.lot),('to_location','=',Location.get_transit_id())],order=[('id', 'DESC')],limit=1)
# if self.unit: return moves[0] if moves else None
# return round(sum([(e.lot_quantity if e.lot_quantity else 0) for e in self.lotqt]),2)
# else:
# return 0
# else:
# return 0
@classmethod @classmethod
def validate(cls, moves): def validate(cls, moves):