| 1 |
from odoo import models, _ |
| 2 |
|
| 3 |
|
| 4 |
class AccountMove(models.Model): |
| 5 |
_inherit = 'account.move' |
| 6 |
|
| 7 |
def reflect_cancelled_sol(self, isCancelled): |
| 8 |
if self.env.user.has_group('point_of_sale.group_pos_user'): |
| 9 |
for invoice in self: |
| 10 |
for pos_order_line in invoice.pos_order_ids.mapped('lines'): |
| 11 |
if pos_order_line.sale_order_line_id: |
| 12 |
if isCancelled and "(Cancelled)" not in pos_order_line.sale_order_line_id.name: |
| 13 |
name = _("%(old_name)s (Cancelled)", old_name=pos_order_line.sale_order_line_id.name) |
| 14 |
pos_order_line.sale_order_line_id.name = name |
| 15 |
elif not isCancelled and "(Cancelled)" in pos_order_line.sale_order_line_id.name: |
| 16 |
pos_order_line.sale_order_line_id.name = pos_order_line.sale_order_line_id.name.replace(" (Cancelled)", "") |
| 17 |
|
| 18 |
def button_cancel(self): |
| 19 |
res = super().button_cancel() |
| 20 |
self.reflect_cancelled_sol(True) |
| 21 |
return res |
| 22 |
|
| 23 |
def action_post(self): |
| 24 |
res = super().action_post() |
| 25 |
self.reflect_cancelled_sol(False) |
| 26 |
return res |
| 27 |
|
| 28 |
def _is_downpayment(self): |
| 29 |
|
| 30 |
self.ensure_one() |
| 31 |
if self.line_ids.sale_line_ids: |
| 32 |
return super()._is_downpayment() |
| 33 |
|
| 34 |
base_lines, _ = self._get_rounded_base_and_tax_lines() |
| 35 |
return base_lines and all('down_payment' in (line['computation_key'] or '').split(',') for line in base_lines) |