diff options
| -rw-r--r-- | fixco_custom/models/reordering_rule.py | 9 | ||||
| -rw-r--r-- | fixco_custom/models/upload_payments.py | 43 | ||||
| -rw-r--r-- | fixco_custom/views/reordering_rule.xml | 2 |
3 files changed, 48 insertions, 6 deletions
diff --git a/fixco_custom/models/reordering_rule.py b/fixco_custom/models/reordering_rule.py index f1e0f9d..c38864e 100644 --- a/fixco_custom/models/reordering_rule.py +++ b/fixco_custom/models/reordering_rule.py @@ -13,6 +13,7 @@ class ReorderingRule(models.Model): vendor_id = fields.Many2one('res.partner', string='Vendor', readonly=True) qty_onhand = fields.Float(string='Qty Onhand', readonly=True) qty_incoming = fields.Float(string='Qty Incoming') + qty_outgoing = fields.Float(string='Qty Outgoing') stock_status = fields.Char('Stock Status',readonly=True) diff_stock = fields.Float(string='Diff Stock') @@ -91,6 +92,7 @@ class ReorderingRule(models.Model): COALESCE(SUM(sq.quantity), 0.0) AS qty_onhand, vmsbm.incoming_qty AS qty_incoming, + vmsbm.outgoing_qty AS qty_outgoing, -- DIFF STOCK FINAL ( @@ -103,13 +105,13 @@ class ReorderingRule(models.Model): CASE WHEN ( COALESCE(SUM(sq.quantity), 0.0) - + vmsbm.incoming_qty + + vmsbm.incoming_qty - vmsbm.outgoing_qty ) < vmsbm.min_stock THEN 'MINUS STOCK' WHEN ( COALESCE(SUM(sq.quantity), 0.0) - + vmsbm.incoming_qty + + vmsbm.incoming_qty - vmsbm.outgoing_qty ) <= (vmsbm.min_stock + vmsbm.buffer_stock) THEN 'LOW STOCK' @@ -127,7 +129,8 @@ class ReorderingRule(models.Model): vmsbm.min_stock, vmsbm.buffer_stock, vmsbm.vendor_id, - vmsbm.incoming_qty + vmsbm.incoming_qty, + vmsbm.outgoing_qty ) """) 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 diff --git a/fixco_custom/views/reordering_rule.xml b/fixco_custom/views/reordering_rule.xml index 85249ad..c71784e 100644 --- a/fixco_custom/views/reordering_rule.xml +++ b/fixco_custom/views/reordering_rule.xml @@ -10,6 +10,7 @@ <field name="buffer_stock"/> <field name="qty_onhand"/> <field name="qty_incoming"/> + <field name="qty_outgoing"/> <field name="vendor_id"/> <field name="diff_stock"/> <field name="stock_status"/> @@ -30,6 +31,7 @@ <field name="buffer_stock"/> <field name="qty_onhand"/> <field name="qty_incoming"/> + <field name="qty_outgoing"/> <field name="vendor_id"/> <field name="diff_stock"/> <field name="stock_status"/> |
