Deduce ignored sale quantity from credit limit

Closes #12226
This commit is contained in:
Cédric Krier
2023-05-26 17:11:38 +02:00
parent ac74f92f84
commit b68a8d6598
4 changed files with 27 additions and 3 deletions
+1
View File
@@ -1,3 +1,4 @@
* Deduce ignored sale quantity from credit limit
Version 6.8.0 - 2023-05-01
--------------------------
+1
View File
@@ -10,4 +10,5 @@ def register():
Pool.register(
party.Party,
sale.Sale,
sale.Line,
module='sale_credit_limit', type_='model')
+2 -2
View File
@@ -31,8 +31,8 @@ class Party(metaclass=PoolMeta):
for sale in sales:
amount = 0
for line in sale.lines:
quantity = line.quantity
if (line.type != 'line') or (quantity <= 0):
quantity = line.credit_limit_quantity
if quantity is None:
continue
for invoice_line in line.invoice_lines:
if invoice_line.type != 'line':
+23 -1
View File
@@ -1,7 +1,7 @@
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
from trytond.model import ModelView, Workflow
from trytond.pool import PoolMeta
from trytond.pool import Pool, PoolMeta
class Sale(metaclass=PoolMeta):
@@ -25,3 +25,25 @@ class Sale(metaclass=PoolMeta):
party.check_credit_limit(
sale.credit_limit_amount, origin=str(sale))
super(Sale, cls).confirm(sales)
class Line(metaclass=PoolMeta):
__name__ = 'sale.line'
@property
def credit_limit_quantity(self):
pool = Pool()
UoM = pool.get('product.uom')
if (self.type != 'line') or (self.quantity <= 0):
return None
quantity = self.quantity
if self.sale.invoice_method == 'shipment':
for move in self.moves_ignored:
quantity -= UoM.compute_qty(
move.uom, move.quantity, self.unit, round=False)
for invoice_line in self.invoice_lines:
if invoice_line.invoice in self.sale.invoices_ignored:
quantity -= UoM.compute_qty(
invoice_line.unit, invoice_line.quantity, self.unit,
round=False)
return quantity