summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2024-04-23 10:41:48 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2024-04-23 10:41:48 +0700
commit2fc3d45984feaf591fbd74f0ba04b692486311ed (patch)
tree87a8ff2d2bd0fef2fe5cbb1f4e1a12b2b0eb3f4c
parent5dc329c18c278d8eaed23cfb0ea060ac7685cea2 (diff)
parent391d7a3b93eff3eabee371b35ec5287e1f0afdd2 (diff)
Merge branch 'production' into feature/request-by-abl
-rw-r--r--indoteknik_custom/models/automatic_purchase.py97
-rwxr-xr-xindoteknik_custom/models/purchase_order.py48
-rw-r--r--indoteknik_custom/models/purchasing_job.py2
-rw-r--r--indoteknik_custom/models/purchasing_job_multi_update.py2
4 files changed, 69 insertions, 80 deletions
diff --git a/indoteknik_custom/models/automatic_purchase.py b/indoteknik_custom/models/automatic_purchase.py
index d3158182..32a7d9dd 100644
--- a/indoteknik_custom/models/automatic_purchase.py
+++ b/indoteknik_custom/models/automatic_purchase.py
@@ -174,14 +174,17 @@ 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)
if qty_pj > qty_outgoing_pj:
- raise UserError('Qty yang anda beli lebih dari qty outgoing')
+ 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()
- if not self.apo_type =='reordering':
- self.check_qty_po()
+ # if not self.apo_type =='reordering':
+ # self.check_qty_po()
PRODUCT_PER_PO = 20
@@ -311,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)
@@ -345,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,
@@ -363,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):
@@ -373,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 5c23b9b8..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,20 +508,20 @@ 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
- 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:
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',