Add warning when receiving too much goods from purchase

Closes #12521
This commit is contained in:
Cédric Krier committed 2023-08-24 18:18:15 +02:00
1 parent 8034578805
commit 10525611df
5 files changed
+37 -1

No files matched your search

+1
View File
@@ -1,3 +1,4 @@
* Add warning when receiving too much goods from purchase
* Require unit price only for confirmed purchase
* Do not invoice non purchase line
* Rename UOM to Unit for product supplier
+4
View File
@@ -13,5 +13,9 @@ class PurchaseQuotationError(ValidationError):
pass
class PurchaseMoveQuantity(UserWarning):
pass
class PartyLocationError(UserError):
pass
+3
View File
@@ -27,6 +27,9 @@ this repository contains the full copyright notices and license terms. -->
<record model="ir.message" id="msg_purchase_line_delete_cancel_draft">
<field name="text">To delete line "%(line)s" you must cancel or reset to draft purchase "%(purchase)s".</field>
</record>
<record model="ir.message" id="msg_purchase_line_move_quantity">
<field name="text">The purchase line "%(line)s" is moving %(extra)s in addition to the %(quantity)s ordered.</field>
</record>
<record model="ir.message" id="msg_purchase_modify_header_draft">
<field name="text">To modify the header of purchase "%(purchase)s", it must be in draft state.</field>
</record>
+23 -1
View File
@@ -30,7 +30,8 @@ from trytond.transaction import Transaction
from trytond.wizard import (
Button, StateAction, StateTransition, StateView, Wizard)
from .exceptions import PartyLocationError, PurchaseQuotationError
from .exceptions import (
PartyLocationError, PurchaseMoveQuantity, PurchaseQuotationError)
def get_shipments_returns(model_name):
@@ -1805,6 +1806,27 @@ class Line(sequence_ordered(), ModelSQL, ModelView):
move.unit, move.quantity, self.unit)
return quantity
def check_move_quantity(self):
pool = Pool()
Lang = pool.get('ir.lang')
Warning = pool.get('res.user.warning')
lang = Lang.get()
move_type = 'in' if self.quantity >= 0 else 'return'
quantity = (
self._get_move_quantity(move_type)
- self._get_shipped_quantity(move_type))
if quantity < 0:
warning_name = Warning.format(
'check_move_quantity', [self])
if Warning.check(warning_name):
raise PurchaseMoveQuantity(warning_name, gettext(
'purchase.msg_purchase_line_move_quantity',
line=self.rec_name,
extra=lang.format_number_symbol(
-quantity, self.unit),
quantity=lang.format_number_symbol(
self.quantity, self.unit)))
def _get_move_invoice_lines(self, move_type):
'Return the invoice lines that should be shipped'
if self.purchase.invoice_method in {'order', 'manual'}:
+6
View File
@@ -68,6 +68,12 @@ class ShipmentIn(metaclass=PoolMeta):
@Workflow.transition('received')
@process_purchase('incoming_moves')
def receive(cls, shipments):
pool = Pool()
PurchaseLine = pool.get('purchase.line')
for shipment in shipments:
for move in shipment.incoming_moves:
if isinstance(move.origin, PurchaseLine):
move.origin.check_move_quantity()
super(ShipmentIn, cls).receive(shipments)
@classmethod