This commit is contained in:
2026-01-17 16:54:51 +01:00
parent 39c9d83f1b
commit 5d7d0ffe5b

View File

@@ -174,7 +174,7 @@ class Fee(ModelSQL,ModelView):
return round(self.price / self.quantity,4)
elif self.mode == 'perqt':
return self.price
elif self.mode == 'pprice':
elif self.mode == 'pprice' or self.mode == 'pcost':
if self.line and self.price:
return round(self.price * Decimal(self.line.unit_price) / 100,4)
if self.sale_line and self.price:
@@ -297,46 +297,48 @@ class Fee(ModelSQL,ModelView):
@classmethod
def create(cls, vlist):
vlist = [x.copy() for x in vlist]
records = super(Fee, cls).create(vlist)
fees = super(Fee, cls).create(vlist)
qt_sh = Decimal(0)
qt_line = Decimal(0)
unit = None
for record in records:
for fee in fees:
FeeLots = Pool().get('fee.lots')
Lots = Pool().get('lot.lot')
LotQt = Pool().get('lot.qt')
if record.line:
for l in record.line.lots:
if fee.line:
for l in fee.line.lots:
#if l.lot_type == 'physic':
fl = FeeLots()
fl.fee = record.id
fl.fee = fee.id
fl.lot = l.id
fl.line = l.line.id
FeeLots.save([fl])
qt_line += l.get_current_quantity_converted()
unit = l.line.unit
if record.sale_line:
for l in record.sale_line.lots:
if fee.sale_line:
for l in fee.sale_line.lots:
#if l.lot_type == 'physic':
fl = FeeLots()
fl.fee = record.id
fl.fee = fee.id
fl.lot = l.id
fl.sale_line = l.sale_line.id
FeeLots.save([fl])
if record.shipment_in:
if record.shipment_in.state == 'draft'or record.shipment_in.state == 'started':
lots = Lots.search(['lot_shipment_in','=',record.shipment_in.id])
qt_line += l.get_current_quantity_converted()
unit = l.line.unit
if fee.shipment_in:
if fee.shipment_in.state == 'draft'or fee.shipment_in.state == 'started':
lots = Lots.search(['lot_shipment_in','=',fee.shipment_in.id])
if lots:
for l in lots:
#if l.lot_type == 'physic':
fl = FeeLots()
fl.fee = record.id
fl.fee = fee.id
fl.lot = l.id
FeeLots.save([fl])
qt_sh += l.get_current_quantity_converted()
unit = l.line.unit
else:
lqts = LotQt.search(['lot_shipment_in','=',record.shipment_in.id])
lqts = LotQt.search(['lot_shipment_in','=',fee.shipment_in.id])
if lqts:
for l in lqts:
qt_sh += l.lot_p.get_current_quantity_converted()
@@ -344,45 +346,45 @@ class Fee(ModelSQL,ModelView):
else:
raise UserError("You cannot add fee on received shipment!")
type = record.type
type = fee.type
if type == 'ordered':
Purchase = Pool().get('purchase.purchase')
PurchaseLine = Pool().get('purchase.line')
pl = PurchaseLine()
pl.product = record.product
if record.line:
pl.product = fee.product
if fee.line or fee.sale_line:
pl.quantity = round(qt_line,5)
if record.shipment_in:
if fee.shipment_in:
pl.quantity = round(qt_sh,5)
logger.info("CREATE_PURHCASE_FOR_FEE_QT:%s",pl.quantity)
pl.unit = unit
pl.fee_ = record.id
if record.price:
pl.unit_price = round(Decimal(record.price),4)
pl.fee_ = fee.id
if fee.price:
pl.unit_price = round(Decimal(fee.get_price_per_qt()),4)
p = Purchase()
p.lines = [pl]
p.party = record.supplier
p.party = fee.supplier
if p.party.addresses:
p.invoice_address = p.party.addresses[0]
p.currency = record.currency
p.currency = fee.currency
p.line_type = 'service'
Purchase.save([p])
#if reception of moves done we need to generate accrual for fee
StockMove = Pool().get('stock.move')
feelots = FeeLots.search(['fee','=',record.id])
for fl in feelots:
move = fl.lot.get_received_move()
if move:
Warning = Pool().get('res.user.warning')
warning_name = Warning.format("Lot ever received", [])
if Warning.check(warning_name):
raise UserWarning(warning_name,
"By clicking yes, an accrual for this fee will be created")
AccountMove = Pool().get('account.move')
account_move = move._get_account_stock_move_fee(record)
AccountMove.save([account_move])
if not fee.sale_line:
feelots = FeeLots.search(['fee','=',fee.id])
for fl in feelots:
move = fl.lot.get_received_move()
if move:
Warning = Pool().get('res.user.warning')
warning_name = Warning.format("Lot ever received", [])
if Warning.check(warning_name):
raise UserWarning(warning_name,
"By clicking yes, an accrual for this fee will be created")
AccountMove = Pool().get('account.move')
account_move = move._get_account_stock_move_fee(fee)
AccountMove.save([account_move])
return records
return fees
class FeeLots(ModelSQL,ModelView):