diff options
| author | Mqdd <ahmadmiqdad27@gmail.com> | 2025-12-03 09:30:44 +0700 |
|---|---|---|
| committer | Mqdd <ahmadmiqdad27@gmail.com> | 2025-12-03 09:30:44 +0700 |
| commit | 01c6652a82d2f2b78b78f27def6d97b1d4ae37da (patch) | |
| tree | 1c1664b3a9d8e0c18dca1d12c57df844f5845274 | |
| parent | 860187e158fff35cc8f6bd5169583ff5ccd78ffa (diff) | |
| parent | 015269c0268f2cd9a38ad708c8e26bf85a79fcf3 (diff) | |
Merge branch 'odoo-backup' of https://bitbucket.org/altafixco/indoteknik-addons into cr_renca_find
merge
| -rw-r--r-- | indoteknik_custom/models/requisition.py | 40 |
1 files changed, 26 insertions, 14 deletions
diff --git a/indoteknik_custom/models/requisition.py b/indoteknik_custom/models/requisition.py index bcdafb12..64ef4fc8 100644 --- a/indoteknik_custom/models/requisition.py +++ b/indoteknik_custom/models/requisition.py @@ -77,9 +77,20 @@ class Requisition(models.Model): vals['number'] = self.env['ir.sequence'].next_by_code('requisition') or '0' result = super(Requisition, self).create(vals) return result - + + def check_product_line_to_so(self): + for req in self: + for prod_line in req.requisition_lines: + match = self.env['sale.order.line'].search([ + ('product_id', '=', prod_line.product_id.id), ('order_id', '=', req.sale_order_id.id) + ]) + if match: + raise UserError ('Product sudah di SO tidak approve/create PO') + + def button_approve(self): state = ['done', 'sale'] + self.check_product_line_to_so() if self.sale_order_id.state in state: raise UserError('SO sudah Confirm, akan berakibat double Purchase melalui PJ') if self.env.user.id not in [21, 19, 28]: @@ -90,6 +101,7 @@ class Requisition(models.Model): self.merchandise_approve = True def create_po_from_requisition(self): + self.check_product_line_to_so() if not self.sales_approve and not self.merchandise_approve: raise UserError('Harus Di Approve oleh Darren atau Rafly') if not self.requisition_lines: @@ -98,9 +110,9 @@ class Requisition(models.Model): raise UserError('Sudah pernah di create PO') if not self.sale_order_id: raise UserError('Tidak ada link dengan Sales Order, tidak bisa dihitung sebagai Plafon Qty di PO') - + vendor_ids = self.env['requisition.line'].read_group([ - ('requisition_id', '=', self.id), + ('requisition_id', '=', self.id), ('partner_id', '!=', False) ], fields=['partner_id'], groupby=['partner_id']) @@ -116,7 +128,7 @@ class Requisition(models.Model): 'type': 'ir.actions.act_window', 'domain': [('id', 'in', po_ids)], } - + def create_po_by_vendor(self, vendor_id): current_time = datetime.now() @@ -137,7 +149,7 @@ class Requisition(models.Model): } domain = [ - ('requisition_id', '=', self.id), + ('requisition_id', '=', self.id), ('partner_id', '=', vendor_id), ('qty_purchase', '>', 0) ] @@ -151,8 +163,8 @@ class Requisition(models.Model): new_po.name = new_po.name + "/R/" + str(i + 1) po_ids.append(new_po.id) lines = requisition_line.search( - domain, - offset=i * PRODUCT_PER_PO, + domain, + offset=i * PRODUCT_PER_PO, limit=PRODUCT_PER_PO ) tax = [22] @@ -179,7 +191,7 @@ class Requisition(models.Model): self.is_po = True return po_ids - + # def create_po_from_requisition(self): # if not self.requisition_lines: # raise UserError('Tidak ada Lines, belum bisa create PO') @@ -187,7 +199,7 @@ class Requisition(models.Model): # raise UserError('Sudah pernah di create PO') # current_time = datetime.now() # vendor_ids = self.env['requisition.line'].read_group([('requisition_id', '=', self.id), ('partner_id', '!=', False)], fields=['partner_id'], groupby=['partner_id']) - + # counter_po_number = 0 # po_ids = [] # for vendor in vendor_ids: @@ -203,7 +215,7 @@ class Requisition(models.Model): # 'note_description': 'from Purchase Requisition' # } # param_requisition_line = [ - # ('requisition_id', '=', self.id), + # ('requisition_id', '=', self.id), # ('partner_id', '=', vendor['partner_id'][0]), # ('qty_purchase', '>', 0) # ] @@ -238,7 +250,7 @@ class Requisition(models.Model): # tax = [22] # param_line = { - + # 'sequence': count, # 'product_id': product.product_id.id, # 'product_qty': product.qty_purchase, @@ -251,7 +263,7 @@ class Requisition(models.Model): # new_line = self.env['purchase.order.line'].create([param_line]) # if new_po: # new_line.write({ - # 'order_id': new_po.id, + # 'order_id': new_po.id, # }) # product.current_po_id = new_po.id # product.current_po_line_id = new_line.id @@ -298,7 +310,7 @@ class RequisitionLine(models.Model): taxes = 24 human_last_update = purchase_price.human_last_update or datetime.min system_last_update = purchase_price.system_last_update or datetime.min - + #if purchase_price.taxes_product_id.type_tax_use == 'purchase': price = purchase_price.product_price taxes = purchase_price.taxes_product_id.id or 24 @@ -307,7 +319,7 @@ class RequisitionLine(models.Model): #if purchase_price.taxes_system_id.type_tax_use == 'purchase': price = purchase_price.system_price taxes = purchase_price.taxes_system_id.id or 24 - + return price, taxes @api.onchange('price_unit') |
