mirror of
https://gitlab.com/hibou-io/hibou-odoo/suite.git
synced 2025-01-20 12:37:31 +02:00
IMP sale_line_change with tests and Dropshipping check
If a changed line relates to a purchase order that is not cancelled, raises an exception with the name(s) of the purchase orders.
This commit is contained in:
committed by
Leighton Pennicott
parent
32864d7854
commit
8f0d07ca4b
@@ -1,4 +1,5 @@
|
||||
from odoo import api, fields, models
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
class SaleLineChangeOrder(models.TransientModel):
|
||||
@@ -53,10 +54,19 @@ class SaleLineChangeOrderLine(models.TransientModel):
|
||||
}
|
||||
|
||||
def _apply(self):
|
||||
self._apply_clean_dropship()
|
||||
self._apply_clean_existing_moves()
|
||||
self._apply_new_values()
|
||||
self._apply_procurement()
|
||||
|
||||
def _apply_clean_dropship(self):
|
||||
po_line_model = self.env['purchase.order.line'].sudo()
|
||||
po_lines = po_line_model.search([('sale_line_id', 'in', self.mapped('sale_line_id.id'))])
|
||||
|
||||
if po_lines and po_lines.filtered(lambda l: l.order_id.state != 'cancel'):
|
||||
names = ', '.join(po_lines.filtered(lambda l: l.order_id.state != 'cancel').mapped('order_id.name'))
|
||||
raise ValidationError('One or more lines has existing non-cancelled Purchase Orders associated: ' + names)
|
||||
|
||||
def _apply_clean_existing_moves(self):
|
||||
moves = self.mapped('sale_line_id.move_ids').filtered(lambda m: m.state != 'done')
|
||||
moves._action_cancel()
|
||||
|
||||
Reference in New Issue
Block a user