diff options
Diffstat (limited to 'fixco_custom/models/upload_payments.py')
| -rw-r--r-- | fixco_custom/models/upload_payments.py | 43 |
1 files changed, 40 insertions, 3 deletions
diff --git a/fixco_custom/models/upload_payments.py b/fixco_custom/models/upload_payments.py index c7e144f..58f8038 100644 --- a/fixco_custom/models/upload_payments.py +++ b/fixco_custom/models/upload_payments.py @@ -78,8 +78,34 @@ class UploadPayments(models.Model): for move in invoice: move._register_payment_automatically(line.date_invoice) - - + + def queue_job(self): + self.date_upload = fields.Datetime.now() + + lines = self.payments_lines.filtered(lambda l: not l.payment_id) + + existing_jobs = self.env['queue.job'].search([ + ('model_name', '=', 'upload.payments.line'), + ('method_name', '=', 'action_create_payments'), + ('res_id', 'in', lines.ids), + ('state', '!=', 'error'), + ]) + + existing_res_ids = set(existing_jobs.mapped('res_id')) + + jobs_to_create = [] + for line in lines: + if line.id in existing_res_ids: + continue + jobs_to_create.append({ + 'name': f'Upload Payments {line.no_invoice}', + 'model_name': 'upload.payments.line', + 'method_name': 'action_create_payments', + 'res_id': line.id, + }) + + self.env['queue.job'].create(jobs_to_create) + class UploadPaymentsLine(models.Model): _name = "upload.payments.line" @@ -90,4 +116,15 @@ class UploadPaymentsLine(models.Model): no_invoice = fields.Char('Invoice Number', required=True) date_invoice = fields.Date('Invoice Date', required=True) move_id = fields.Many2one('account.move', string='Invoice') - payment_id = fields.Many2one('account.payment', string='Created Payment')
\ No newline at end of file + payment_id = fields.Many2one('account.payment', string='Created Payment') + + def action_create_payments(self): + self.ensure_one() + invoice = self.env['account.move'].search([ + ('invoice_marketplace', '=', self.no_invoice), + ('state', '=', 'posted'), + ('payment_state', '!=', 'paid'), + ]) + + for move in invoice: + move._register_payment_automatically(self.date_invoice)
\ No newline at end of file |
