diff options
Diffstat (limited to 'fixco_custom/models/sale.py')
| -rwxr-xr-x | fixco_custom/models/sale.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/fixco_custom/models/sale.py b/fixco_custom/models/sale.py index a36be0f..b77c92c 100755 --- a/fixco_custom/models/sale.py +++ b/fixco_custom/models/sale.py @@ -11,6 +11,40 @@ class SaleOrder(models.Model): address = fields.Char('Address') note_by_buyer = fields.Char('Note By Buyer') + count_payment = fields.Integer('Count Payment', compute='_compute_count_payment') + + def _compute_count_payment(self): + for rec in self: + if rec.invoice_ids: + invoice_ids_set = set(rec.invoice_ids.ids) + payments = self.env['account.payment'].search([]).filtered( + lambda p: any(inv.id in invoice_ids_set for inv in p.reconciled_invoice_ids) + ) + rec.count_payment = len(payments) + else: + rec.count_payment = 0 + + + def action_view_related_payment(self): + self.ensure_one() + + for rec in self: + if rec.invoice_ids: + invoice_ids_set = set(rec.invoice_ids.ids) + payments = self.env['account.payment'].search([]).filtered( + lambda p: any(inv.id in invoice_ids_set for inv in p.reconciled_invoice_ids) + ) + + return { + 'name': 'Payments', + 'type': 'ir.actions.act_window', + 'res_model': 'account.payment', + 'view_mode': 'tree,form', + 'target': 'current', + 'domain': [('id', 'in', payments.ids)], + } + + def _check_duplicate_order_id(self): for rec in self: so_duplicate = self.search([ |
