From a87e58a2d7bbfb9103c6bb9ca8b17fefeadb3275 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Wed, 17 Apr 2024 15:24:47 +0700 Subject: margin po --- indoteknik_custom/models/purchase_order.py | 50 +++++++++++++++--------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index 5c23b9b8..71ac0655 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -498,9 +498,9 @@ class PurchaseOrder(models.Model): ('order_id', '=', line.sale_id.id) ], limit=1, order='price_reduce_taxexcl') - sum_so_margin += sale_order_line.item_margin - # sales_price = sale_order_line.price_reduce_taxexcl * sale_order_line.product_uom_qty - sales_price = sale_order_line.price_reduce_taxexcl * po_line.product_qty + sum_so_margin = sale_order_line.item_margin * po_line.product_qty + sales_price = sale_order_line.price_reduce_taxexcl * sale_order_line.product_uom_qty + # sales_price = sale_order_line.price_reduce_taxexcl * po_line.product_qty if sale_order_line.order_id.shipping_cost_covered == 'indoteknik': sales_price -= sale_order_line.delivery_amt_line if sale_order_line.order_id.fee_third_party > 0: @@ -512,16 +512,16 @@ class PurchaseOrder(models.Model): real_item_margin = sales_price - purchase_price sum_margin += real_item_margin - if sum_so_margin != 0 and sum_sales_price != 0 and sum_margin != 0: - self.total_so_margin = sum_so_margin - self.total_so_percent_margin = round((sum_so_margin / sum_sales_price), 2) * 100 - self.total_margin = sum_margin - self.total_percent_margin = round((sum_margin / sum_sales_price), 2) * 100 - else: - self.total_margin = 0 - self.total_percent_margin = 0 - self.total_so_margin = 0 - self.total_so_percent_margin = 0 + if sum_so_margin != 0 and sum_sales_price != 0 and sum_margin != 0: + self.total_so_margin = sum_so_margin + self.total_so_percent_margin = round((sum_so_margin / sum_sales_price), 2) * 100 + self.total_margin = sum_margin + self.total_percent_margin = round((sum_margin / sum_sales_price), 2) * 100 + else: + self.total_margin = 0 + self.total_percent_margin = 0 + self.total_so_margin = 0 + self.total_so_percent_margin = 0 # def compute_total_margin_from_apo(self): # purchase_price_dict = {} @@ -545,8 +545,8 @@ class PurchaseOrder(models.Model): # sum_so_margin += sale_order_line.item_margin - # sales_price = sale_order_line.price_reduce_taxexcl * line.qty_so - # # sales_price = sale_order_line.price_reduce_taxexcl * lines.product_qty + # # sales_price = sale_order_line.price_reduce_taxexcl * line.qty_so + # sales_price = sale_order_line.price_reduce_taxexcl * lines.product_qty # if sale_order_line.order_id.shipping_cost_covered == 'indoteknik': # sales_price -= sale_order_line.delivery_amt_line @@ -569,16 +569,16 @@ class PurchaseOrder(models.Model): # real_item_margin = sales_price - purchase_price # sum_margin += real_item_margin - # if sum_so_margin != 0 and sum_sales_price != 0 and sum_margin != 0: - # self.total_so_margin = sum_so_margin - # self.total_so_percent_margin = round((sum_so_margin / sum_sales_price), 2) * 100 - # self.total_margin = sum_margin - # self.total_percent_margin = round((sum_margin / sum_sales_price), 2) * 100 - # else: - # self.total_margin = 0 - # self.total_percent_margin = 0 - # self.total_so_margin = 0 - # self.total_so_percent_margin = 0 + # if sum_so_margin != 0 and sum_sales_price != 0 and sum_margin != 0: + # self.total_so_margin = sum_so_margin + # self.total_so_percent_margin = round((sum_so_margin / sum_sales_price), 2) * 100 + # self.total_margin = sum_margin + # self.total_percent_margin = round((sum_margin / sum_sales_price), 2) * 100 + # else: + # self.total_margin = 0 + # self.total_percent_margin = 0 + # self.total_so_margin = 0 + # self.total_so_percent_margin = 0 def compute_amt_total_without_service(self): for order in self: -- cgit v1.2.3 From 839609fda8050e4a97d67a607a6999b20d9a4b0a Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Wed, 17 Apr 2024 15:26:49 +0700 Subject: margin po --- indoteknik_custom/models/purchase_order.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index 71ac0655..99c71e84 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -499,8 +499,8 @@ class PurchaseOrder(models.Model): ], limit=1, order='price_reduce_taxexcl') sum_so_margin = sale_order_line.item_margin * po_line.product_qty - sales_price = sale_order_line.price_reduce_taxexcl * sale_order_line.product_uom_qty - # sales_price = sale_order_line.price_reduce_taxexcl * po_line.product_qty + # sales_price = sale_order_line.price_reduce_taxexcl * sale_order_line.product_uom_qty + sales_price = sale_order_line.price_reduce_taxexcl * po_line.product_qty if sale_order_line.order_id.shipping_cost_covered == 'indoteknik': sales_price -= sale_order_line.delivery_amt_line if sale_order_line.order_id.fee_third_party > 0: -- cgit v1.2.3 From 3d3e6660b991e5170c6629b86790630636b4c9f9 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Wed, 17 Apr 2024 15:38:54 +0700 Subject: margin po --- indoteknik_custom/models/purchase_order.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index 99c71e84..a1c9f134 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -498,7 +498,7 @@ class PurchaseOrder(models.Model): ('order_id', '=', line.sale_id.id) ], limit=1, order='price_reduce_taxexcl') - sum_so_margin = sale_order_line.item_margin * po_line.product_qty + sum_so_margin += sale_order_line.item_margin # sales_price = sale_order_line.price_reduce_taxexcl * sale_order_line.product_uom_qty sales_price = sale_order_line.price_reduce_taxexcl * po_line.product_qty if sale_order_line.order_id.shipping_cost_covered == 'indoteknik': -- cgit v1.2.3 From 53a313d291039c88476bedfb226d672ebb81e25b Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Wed, 17 Apr 2024 15:49:17 +0700 Subject: modified function check_qty_apo --- indoteknik_custom/models/automatic_purchase.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/indoteknik_custom/models/automatic_purchase.py b/indoteknik_custom/models/automatic_purchase.py index d3158182..a5c1041a 100644 --- a/indoteknik_custom/models/automatic_purchase.py +++ b/indoteknik_custom/models/automatic_purchase.py @@ -175,8 +175,10 @@ class AutomaticPurchase(models.Model): qty_pj += line.product_qty + lines.qty_purchase qty_outgoing_pj += line.qty_outgoing + id_po = [] if qty_pj > qty_outgoing_pj: - raise UserError('Qty yang anda beli lebih dari qty outgoing') + id_po.append(po.name) + raise UserError('Qty yang anda beli lebih dari qty outgoing. %s' %po) def create_po_by_vendor(self, vendor_id): current_time = datetime.now() -- cgit v1.2.3 From fa1f56ebf9a00221477ec782e68db5009ba60f82 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Wed, 17 Apr 2024 15:58:43 +0700 Subject: modify function check_qty_apo --- indoteknik_custom/models/automatic_purchase.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indoteknik_custom/models/automatic_purchase.py b/indoteknik_custom/models/automatic_purchase.py index a5c1041a..4ea43a23 100644 --- a/indoteknik_custom/models/automatic_purchase.py +++ b/indoteknik_custom/models/automatic_purchase.py @@ -178,7 +178,7 @@ class AutomaticPurchase(models.Model): id_po = [] if qty_pj > qty_outgoing_pj: id_po.append(po.name) - raise UserError('Qty yang anda beli lebih dari qty outgoing. %s' %po) + raise UserError('Qty yang anda beli lebih dari qty outgoing. %s' %id_po) def create_po_by_vendor(self, vendor_id): current_time = datetime.now() -- cgit v1.2.3 From 71a3d1e9c253c995a6f7cca564fd171254e9a0e6 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 18 Apr 2024 11:36:39 +0700 Subject: margin po --- indoteknik_custom/models/automatic_purchase.py | 93 ++++++++++------------ indoteknik_custom/models/purchase_order.py | 4 +- indoteknik_custom/models/purchasing_job.py | 2 +- .../models/purchasing_job_multi_update.py | 2 +- 4 files changed, 44 insertions(+), 57 deletions(-) diff --git a/indoteknik_custom/models/automatic_purchase.py b/indoteknik_custom/models/automatic_purchase.py index 4ea43a23..108dcf58 100644 --- a/indoteknik_custom/models/automatic_purchase.py +++ b/indoteknik_custom/models/automatic_purchase.py @@ -174,10 +174,11 @@ class AutomaticPurchase(models.Model): for line in po.order_line: qty_pj += line.product_qty + lines.qty_purchase qty_outgoing_pj += line.qty_outgoing + id_po = [] + if qty_pj > qty_outgoing_pj: + id_po.append(po.name) - id_po = [] if qty_pj > qty_outgoing_pj: - id_po.append(po.name) raise UserError('Qty yang anda beli lebih dari qty outgoing. %s' %id_po) def create_po_by_vendor(self, vendor_id): @@ -313,28 +314,18 @@ class AutomaticPurchase(models.Model): sales_order_purchase_match = self.env['sales.order.purchase.match'].create([matches_po_line]) - def generate_regular_purchase(self): - po = self.env['purchase.order'].search([ - ('state', '=', 'draft') - ]) - if po: - raise UserError('Ada PO yang statusnya draft, proses dulu') - if self.apo_type == 'reordering': - raise UserError('Tombol ini hanya untuk Regular Fulfill SO') - if self.vendor_id: - raise UserError('Vendor tidak dapat diisi jika Regular Fulfill SO') - if self.purchase_lines: - raise UserError('Sudah digenerate sebelumnya, hapus line terlebih dahulu') - - self.responsible_id = self.env.user.id - self.date_doc = datetime.utcnow() + def generate_regular_purchase(self, jobs): + current_time = datetime.utcnow() + automatic_purchase = self.env['automatic.purchase'].create([{ + 'apo_type': 'regular', + 'date_doc': current_time, + }]) + automatic_purchase.responsible_id = self.env.user.id + automatic_purchase.date_doc = datetime.utcnow() #TODO must add order by for fifo mechanism #change the view of v.purchasing.job and use order by in query - query = [ - ('action', '=', 'kurang') - ] - jobs = self.env['v.purchasing.job'].search(query) + count = 0 for job in jobs: qty_purchase = job.outgoing - (job.onhand + job.incoming) @@ -347,11 +338,11 @@ class AutomaticPurchase(models.Model): purchase_pricelist = self.env['purchase.pricelist'].search(domain, order=orderby, limit=1) vendor_id = purchase_pricelist.vendor_id - price, taxes = self._get_valid_purchase_price(purchase_pricelist) + 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': self.id, + 'automatic_purchase_id': automatic_purchase.id, 'product_id': job.product_id.id, 'qty_purchase': qty_purchase, 'qty_available': qty_available, @@ -365,9 +356,9 @@ class AutomaticPurchase(models.Model): }]) count += 1 _logger.info('Create Automatic Purchase Line %s' % job.product_id.name) - self.notification = "Automatic PO Created %s Lines" % count - self._create_sales_matching() - self._create_sync_purchasing_job(jobs) + automatic_purchase.notification = "Automatic PO Created %s Lines" % count + automatic_purchase._create_sales_matching() + automatic_purchase._create_sync_purchasing_job(jobs) print(1) def _create_sales_matching(self): @@ -375,34 +366,30 @@ class AutomaticPurchase(models.Model): domain = [ ('product_id', '=', line.product_id.id) ] - sales = self.env['v.sales.outstanding'].search(domain) - for sale in sales: - existing_match = self.env['automatic.purchase.sales.match'].search([ - ('automatic_purchase_id', '=', self.id), - ('sale_id', '=', sale.sale_id.id), - ]) + sale = self.env['v.sales.outstanding'].search(domain, limit=1) + + existing_match = self.env['automatic.purchase.sales.match'].search([ + ('automatic_purchase_id', '=', self.id), + ('sale_id', '=', sale.sale_id.id), + ('product_id', '=', sale.product_id.id), + ]) - if not existing_match: - if line.qty_purchase > sale.outgoing: - qty_po = sale.outgoing - else: - qty_po = line.qty_purchase - - self.env['automatic.purchase.sales.match'].create([{ - 'automatic_purchase_id': self.id, - 'sale_id': sale.sale_id.id, - 'sale_line_id': sale.sale_line_id.id, - 'picking_id': sale.picking_id.id, - 'move_id': sale.move_id.id, - 'partner_id': sale.partner_id.id, - 'partner_invoice_id': sale.partner_invoice_id.id, - 'salesperson_id': sale.salesperson_id.id, - 'product_id': sale.product_id.id, - 'qty_so': sale.outgoing, - 'qty_po': qty_po, - }]) - - print(1) + if existing_match: + continue + + self.env['automatic.purchase.sales.match'].create([{ + 'automatic_purchase_id': self.id, + 'sale_id': sale.sale_id.id, + 'sale_line_id': sale.sale_line_id.id, + 'picking_id': sale.picking_id.id, + 'move_id': sale.move_id.id, + 'partner_id': sale.partner_id.id, + 'partner_invoice_id': sale.partner_invoice_id.id, + 'salesperson_id': sale.salesperson_id.id, + 'product_id': sale.product_id.id, + 'qty_so': sale.outgoing, + 'qty_po': line.qty_purchase, + }]) def _create_sync_purchasing_job(self, jobs): date = datetime.utcnow() diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index a1c9f134..caad90d3 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -498,7 +498,7 @@ class PurchaseOrder(models.Model): ('order_id', '=', line.sale_id.id) ], limit=1, order='price_reduce_taxexcl') - sum_so_margin += sale_order_line.item_margin + sum_so_margin += line.qty_po / line.qty_so * sale_order_line.item_margin # sales_price = sale_order_line.price_reduce_taxexcl * sale_order_line.product_uom_qty sales_price = sale_order_line.price_reduce_taxexcl * po_line.product_qty if sale_order_line.order_id.shipping_cost_covered == 'indoteknik': @@ -508,7 +508,7 @@ class PurchaseOrder(models.Model): sum_sales_price += sales_price purchase_price = po_line.price_subtotal if line.purchase_order_id.delivery_amount > 0: - purchase_price += line.delivery_amt_line + purchase_price += po_line.delivery_amt_line real_item_margin = sales_price - purchase_price sum_margin += real_item_margin diff --git a/indoteknik_custom/models/purchasing_job.py b/indoteknik_custom/models/purchasing_job.py index 5fba0a95..deec88d7 100644 --- a/indoteknik_custom/models/purchasing_job.py +++ b/indoteknik_custom/models/purchasing_job.py @@ -162,7 +162,7 @@ class PurchasingJob(models.Model): class OutstandingSales(models.Model): _name = 'v.sales.outstanding' - _auto = False + _auto = False _rec_name = 'move_id' id = fields.Integer() diff --git a/indoteknik_custom/models/purchasing_job_multi_update.py b/indoteknik_custom/models/purchasing_job_multi_update.py index f3d07597..65feba71 100644 --- a/indoteknik_custom/models/purchasing_job_multi_update.py +++ b/indoteknik_custom/models/purchasing_job_multi_update.py @@ -20,7 +20,7 @@ class PurchasingJobMultiUpdate(models.TransientModel): 'status_apo': 'apo', }) - apo = products.generate_request_po() + apo = self.env['automatic.purchase'].generate_regular_purchase(products) return { 'name': _('Automatic Purchase'), 'view_mode': 'tree,form', -- cgit v1.2.3 From 391d7a3b93eff3eabee371b35ec5287e1f0afdd2 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 18 Apr 2024 14:53:16 +0700 Subject: deactivate function check_qty_apo --- indoteknik_custom/models/automatic_purchase.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/indoteknik_custom/models/automatic_purchase.py b/indoteknik_custom/models/automatic_purchase.py index 108dcf58..32a7d9dd 100644 --- a/indoteknik_custom/models/automatic_purchase.py +++ b/indoteknik_custom/models/automatic_purchase.py @@ -183,8 +183,8 @@ class AutomaticPurchase(models.Model): def create_po_by_vendor(self, vendor_id): current_time = datetime.now() - if not self.apo_type =='reordering': - self.check_qty_po() + # if not self.apo_type =='reordering': + # self.check_qty_po() PRODUCT_PER_PO = 20 -- cgit v1.2.3