From eabbbadc5114f6c1edb9ec6bb74a296477f02b5a Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Thu, 14 Dec 2023 14:13:32 +0700 Subject: initial commit purchasing job --- indoteknik_custom/models/purchasing_job.py | 42 ++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 indoteknik_custom/models/purchasing_job.py (limited to 'indoteknik_custom/models/purchasing_job.py') diff --git a/indoteknik_custom/models/purchasing_job.py b/indoteknik_custom/models/purchasing_job.py new file mode 100644 index 00000000..c660b937 --- /dev/null +++ b/indoteknik_custom/models/purchasing_job.py @@ -0,0 +1,42 @@ +from odoo import fields, models, api, tools +import logging + +_logger = logging.getLogger(__name__) + + +class PurchasingJob(models.Model): + _name = 'v.purchasing.job' + _auto = False + _rec_name = 'product_id' + + id = fields.Integer() + product_id = fields.Many2one('product.product', string="Product") + brand = fields.Char(string='Brand') + item_code = fields.Char(string='Item Code') + product = fields.Char(string='Product Name') + onhand = fields.Float(string='OnHand') + incoming = fields.Float(string="Incoming") + outgoing = fields.Float(string="Outgoing") + action = fields.Char(string="Status") + + def init(self): + tools.drop_view_if_exists(self.env.cr, self._table) + self.env.cr.execute(""" + CREATE OR REPLACE VIEW %s AS ( + select product_id as id, product_id, brand, item_code, product, onhand, incoming, outgoing, action + from v_procurement_monitoring_by_product + where action = 'kurang beli' + ) + """ % self._table) + + def open_form_multi_generate_request_po(self): + action = self.env['ir.actions.act_window']._for_xml_id('indoteknik_custom.action_generate_request_po') + action['context'] = { + 'product_ids': [x.id for x in self] + } + return action + + def generate_request_po(self): + # print(1) + for product in self: + print(product) -- cgit v1.2.3 From ce2b8502ab85419096dda2bffaffbec4a096a99f Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Thu, 14 Dec 2023 15:16:55 +0700 Subject: bug fix window multi update --- indoteknik_custom/models/purchasing_job.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'indoteknik_custom/models/purchasing_job.py') diff --git a/indoteknik_custom/models/purchasing_job.py b/indoteknik_custom/models/purchasing_job.py index c660b937..18235d47 100644 --- a/indoteknik_custom/models/purchasing_job.py +++ b/indoteknik_custom/models/purchasing_job.py @@ -30,7 +30,7 @@ class PurchasingJob(models.Model): """ % self._table) def open_form_multi_generate_request_po(self): - action = self.env['ir.actions.act_window']._for_xml_id('indoteknik_custom.action_generate_request_po') + action = self.env['ir.actions.act_window']._for_xml_id('indoteknik_custom.action_purchasing_job_multi_update') action['context'] = { 'product_ids': [x.id for x in self] } @@ -38,5 +38,5 @@ class PurchasingJob(models.Model): def generate_request_po(self): # print(1) - for product in self: - print(product) + for job in self: + print(job.product_id.name) -- cgit v1.2.3 From e2086bc4f96391260fb3430537feddbc25bdde40 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 19 Dec 2023 09:32:09 +0700 Subject: over to nathan --- indoteknik_custom/models/purchasing_job.py | 47 ++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'indoteknik_custom/models/purchasing_job.py') diff --git a/indoteknik_custom/models/purchasing_job.py b/indoteknik_custom/models/purchasing_job.py index 18235d47..43da2458 100644 --- a/indoteknik_custom/models/purchasing_job.py +++ b/indoteknik_custom/models/purchasing_job.py @@ -38,5 +38,52 @@ class PurchasingJob(models.Model): def generate_request_po(self): # print(1) + # TODO create document automatic purchase for job in self: print(job.product_id.name) + + +class OutstandingSales(models.Model): + _name = 'v.sales.outstanding' + _auto = False + _rec_name = 'move_id' + + id = fields.Integer() + move_id = fields.Many2one('stock.move', string='Move') + picking_id = fields.Many2one('stock.picking', string='Picking') + product_id = fields.Many2one('product.product', string='Product') + sale_id = fields.Many2one('sale.order', string='Sale') + sale_line_id = fields.Many2one('sale.order.line', string='Sale Line') + partner_id = fields.Many2one('res.partner', string='Partner') + partner_invoice_id = fields.Many2one('res.partner', string='Invoice Partner') + salesperson_id = fields.Many2one('res.users', string='Salesperson') + origin = fields.Char(string='Origin') + salesperson = fields.Char(string='Sales Name') + item_code = fields.Char(string='Item Code') + product = fields.Char(string='Product') + outgoing = fields.Float(string='Outgoing') + brand = fields.Char(string='Brand') + invoice_partner = fields.Char(string='Invoice Partner') + + def init(self): + tools.drop_view_if_exists(self.env.cr, self._table) + self.env.cr.execute(""" + CREATE OR REPLACE VIEW v_sales_outstanding AS ( + select sm.id, sm.id as move_id, sp.id as picking_id, sm.product_id, so.id as sale_id, + sol.id as sale_line_id, rp.id as partner_id, so.user_id as salesperson_id, so.partner_invoice_id, + sp.origin, rp2.name as salesperson, coalesce(pp.default_code, pt.default_code) as item_code, pt.name as product, + sm.product_uom_qty as outgoing, xm.x_name as brand, rp.name as invoice_partner + from stock_move sm + join stock_picking sp on sp.id = sm.picking_id + join sale_order_line sol on sol.id = sm.sale_line_id + join sale_order so on so.id = sol.order_id + join res_partner rp on rp.id = so.partner_invoice_id + join res_users ru on ru.id = so.user_id + join res_partner rp2 on rp2.id = ru.partner_id + join product_product pp on pp.id = sm.product_id + join product_template pt on pt.id = pp.product_tmpl_id + left join x_manufactures xm on xm.id = pt.x_manufacture + where sp.state in ('draft', 'waiting', 'confirmed', 'assigned') + and sp.name like '%OUT%' + ) + """) -- cgit v1.2.3 From 624e4077925cf1517097da015076dd4385cf286c Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Wed, 27 Dec 2023 10:13:47 +0700 Subject: validate if product have po --- indoteknik_custom/models/purchasing_job.py | 1 + 1 file changed, 1 insertion(+) (limited to 'indoteknik_custom/models/purchasing_job.py') diff --git a/indoteknik_custom/models/purchasing_job.py b/indoteknik_custom/models/purchasing_job.py index 43da2458..09c202d9 100644 --- a/indoteknik_custom/models/purchasing_job.py +++ b/indoteknik_custom/models/purchasing_job.py @@ -18,6 +18,7 @@ class PurchasingJob(models.Model): incoming = fields.Float(string="Incoming") outgoing = fields.Float(string="Outgoing") action = fields.Char(string="Status") + is_po = fields.Boolean(string='Is PO') def init(self): tools.drop_view_if_exists(self.env.cr, self._table) -- cgit v1.2.3 From 5eabba4b2a8a3e1ec233f60c6aa7a0fa7414fd51 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Wed, 27 Dec 2023 13:37:37 +0700 Subject: alert if so have matches po --- indoteknik_custom/models/purchasing_job.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'indoteknik_custom/models/purchasing_job.py') diff --git a/indoteknik_custom/models/purchasing_job.py b/indoteknik_custom/models/purchasing_job.py index 09c202d9..7ac678c4 100644 --- a/indoteknik_custom/models/purchasing_job.py +++ b/indoteknik_custom/models/purchasing_job.py @@ -18,13 +18,12 @@ class PurchasingJob(models.Model): incoming = fields.Float(string="Incoming") outgoing = fields.Float(string="Outgoing") action = fields.Char(string="Status") - is_po = fields.Boolean(string='Is PO') def init(self): tools.drop_view_if_exists(self.env.cr, self._table) self.env.cr.execute(""" CREATE OR REPLACE VIEW %s AS ( - select product_id as id, product_id, brand, item_code, product, onhand, incoming, outgoing, action + select product_id as id, product_id, brand, item_code, product, onhand, incoming, outgoing, action from v_procurement_monitoring_by_product where action = 'kurang beli' ) -- cgit v1.2.3 From c76e3d6126c3d595a6c3c5d6802a9f5e7015f378 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Fri, 9 Feb 2024 09:32:52 +0700 Subject: change request purchasing job --- indoteknik_custom/models/purchasing_job.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indoteknik_custom/models/purchasing_job.py') diff --git a/indoteknik_custom/models/purchasing_job.py b/indoteknik_custom/models/purchasing_job.py index 7ac678c4..4afb3e03 100644 --- a/indoteknik_custom/models/purchasing_job.py +++ b/indoteknik_custom/models/purchasing_job.py @@ -25,7 +25,7 @@ class PurchasingJob(models.Model): CREATE OR REPLACE VIEW %s AS ( select product_id as id, product_id, brand, item_code, product, onhand, incoming, outgoing, action from v_procurement_monitoring_by_product - where action = 'kurang beli' + where action = 'kurang' ) """ % self._table) -- cgit v1.2.3 From d3e3a8abf0ae382442c16a7ac6091c7bb872313f Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Wed, 13 Mar 2024 16:24:13 +0700 Subject: change request purchasing job --- indoteknik_custom/models/purchasing_job.py | 48 +++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) (limited to 'indoteknik_custom/models/purchasing_job.py') diff --git a/indoteknik_custom/models/purchasing_job.py b/indoteknik_custom/models/purchasing_job.py index 4afb3e03..b3c25256 100644 --- a/indoteknik_custom/models/purchasing_job.py +++ b/indoteknik_custom/models/purchasing_job.py @@ -1,5 +1,6 @@ -from odoo import fields, models, api, tools +from odoo import fields, models, api, tools, _ import logging +from datetime import datetime _logger = logging.getLogger(__name__) @@ -39,9 +40,54 @@ class PurchasingJob(models.Model): def generate_request_po(self): # print(1) # TODO create document automatic purchase + + current_time = datetime.utcnow() + + automatic_purchase = self.env['automatic.purchase'].create([{ + 'apo_type': 'regular', + 'date_doc': current_time, + }]) + count = 0 for job in self: print(job.product_id.name) + qty_purchase = job.outgoing - (job.onhand + job.incoming) + qty_available = (job.onhand + job.incoming) - job.outgoing + + domain = [ + ('product_id.id', '=', job.product_id.id), + ] + orderby = 'count_trx_po desc, count_trx_po_vendor desc' + purchase_pricelist = self.env['purchase.pricelist'].search(domain, order=orderby, limit=1) + vendor_id = purchase_pricelist.vendor_id + price, taxes = automatic_purchase._get_valid_purchase_price(purchase_pricelist) + last_po_line = self.env['purchase.order.line'].search([('product_id', '=', job.product_id.id), ('order_id.state', '=', 'done')], order='id desc', limit=1) + + self.env['automatic.purchase.line'].create([{ + 'automatic_purchase_id': automatic_purchase.id, + 'product_id': job.product_id.id, + 'qty_purchase': qty_purchase, + 'qty_available': qty_available, + 'partner_id': vendor_id.id, + 'last_price': price, + 'taxes_id': taxes, + 'subtotal': qty_purchase * price, + 'last_order_id': last_po_line.order_id.id, + 'last_orderline_id': last_po_line.id, + 'brand_id': job.product_id.product_tmpl_id.x_manufacture.id + }]) + automatic_purchase._create_sales_matching() + automatic_purchase._create_sync_purchasing_job(job) + count += 1 + _logger.info('Create Automatic Purchase Line %s' % job.product_id.name) + return { + 'name': _('Automatic Purchase'), + 'view_mode': 'tree,form', + 'res_model': 'automatic.purchase', + 'target': 'current', + 'type': 'ir.actions.act_window', + 'domain': [('id', '=', automatic_purchase.id)], + } class OutstandingSales(models.Model): _name = 'v.sales.outstanding' -- cgit v1.2.3 From b2377426bec8aa334277aac48b0b25f0dfac420f Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Mon, 25 Mar 2024 13:07:44 +0700 Subject: purchasing job feedback --- indoteknik_custom/models/purchasing_job.py | 46 +++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 11 deletions(-) (limited to 'indoteknik_custom/models/purchasing_job.py') diff --git a/indoteknik_custom/models/purchasing_job.py b/indoteknik_custom/models/purchasing_job.py index b3c25256..1c74f0e9 100644 --- a/indoteknik_custom/models/purchasing_job.py +++ b/indoteknik_custom/models/purchasing_job.py @@ -12,6 +12,7 @@ class PurchasingJob(models.Model): id = fields.Integer() product_id = fields.Many2one('product.product', string="Product") + vendor_id = fields.Many2one('res.partner', string="Vendor", compute='compute_vendor_id') brand = fields.Char(string='Brand') item_code = fields.Char(string='Item Code') product = fields.Char(string='Product Name') @@ -19,17 +20,47 @@ class PurchasingJob(models.Model): incoming = fields.Float(string="Incoming") outgoing = fields.Float(string="Outgoing") action = fields.Char(string="Status") + status_apo = fields.Selection([ + ('not_apo', 'Belum APO'), + ('apo', 'APO') + ], string='APO?') + + def compute_vendor_id(self): + for sale in self: + domain = [ + ('product_id', '=', sale.product_id.id) + ] + sales = self.env['v.sales.outstanding'].search(domain) + + vendor_id = False + + if sales: + vendor_id = sales[0].sale_line_id.vendor_id.id + + sale.vendor_id = vendor_id def init(self): tools.drop_view_if_exists(self.env.cr, self._table) self.env.cr.execute(""" CREATE OR REPLACE VIEW %s AS ( - select product_id as id, product_id, brand, item_code, product, onhand, incoming, outgoing, action - from v_procurement_monitoring_by_product - where action = 'kurang' + SELECT + pmp.product_id as id, + pmp.product_id, + pmp.brand, + pmp.item_code, + pmp.product, + pmp.onhand, + pmp.incoming, + pmp.outgoing, + pmp.action, + pjs.status_apo AS status_apo + FROM v_procurement_monitoring_by_product pmp + LEFT JOIN purchasing_job_state pjs ON pjs.purchasing_job_id = pmp.product_id + WHERE pmp.action = 'kurang' ) """ % self._table) + def open_form_multi_generate_request_po(self): action = self.env['ir.actions.act_window']._for_xml_id('indoteknik_custom.action_purchasing_job_multi_update') action['context'] = { @@ -80,14 +111,7 @@ class PurchasingJob(models.Model): automatic_purchase._create_sync_purchasing_job(job) count += 1 _logger.info('Create Automatic Purchase Line %s' % job.product_id.name) - return { - 'name': _('Automatic Purchase'), - 'view_mode': 'tree,form', - 'res_model': 'automatic.purchase', - 'target': 'current', - 'type': 'ir.actions.act_window', - 'domain': [('id', '=', automatic_purchase.id)], - } + return automatic_purchase.id class OutstandingSales(models.Model): _name = 'v.sales.outstanding' -- cgit v1.2.3