[IMP] sale: Unlink the down payment on a SO if the invoice is unlinked
Purpose ======= When we create a downpayment line of SO and when we delete Invoice of downpayment then so line for downpayment is not deleted. Specification ============= Remove the downpayment line in the SO if the related invoice is deleted Task ID :33126
This commit is contained in:
committed by
Yannick Tivisse
parent
752a6843d1
commit
eebeb39da5
@@ -34,6 +34,14 @@ class AccountInvoice(models.Model):
|
||||
if fiscal_position:
|
||||
self.fiscal_position_id = fiscal_position
|
||||
|
||||
@api.multi
|
||||
def unlink(self):
|
||||
downpayment_lines = self.mapped('invoice_line_ids.sale_line_ids').filtered(lambda line: line.is_downpayment)
|
||||
res = super(AccountInvoice, self).unlink()
|
||||
if downpayment_lines:
|
||||
downpayment_lines.unlink()
|
||||
return res
|
||||
|
||||
@api.onchange('partner_id', 'company_id')
|
||||
def _onchange_delivery_address(self):
|
||||
addr = self.partner_id.address_get(['delivery'])
|
||||
|
||||
@@ -1209,7 +1209,7 @@ class SaleOrderLine(models.Model):
|
||||
|
||||
@api.multi
|
||||
def unlink(self):
|
||||
if self.filtered(lambda x: x.state in ('sale', 'done')):
|
||||
if self.filtered(lambda line: line.state in ('sale', 'done') and (line.invoice_lines or not line.is_downpayment)):
|
||||
raise UserError(_('You can not remove an order line once the sales order is confirmed.\nYou should rather set the quantity to 0.'))
|
||||
return super(SaleOrderLine, self).unlink()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user