summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2024-06-19 11:53:57 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2024-06-19 11:53:57 +0700
commita7eda38c3a1146a33da50ae6a6f87cbc61bbfc97 (patch)
treee2c9add5b5525f2d7b5ab49fa1a9e2a44aa40604
parent20ae84eb89409a75b6ba024a9d9e06bdc593a480 (diff)
change request payment_schedule and fix sales order fulfilment bug
-rwxr-xr-xindoteknik_custom/models/purchase_order.py102
-rw-r--r--indoteknik_custom/models/report_stock_forecasted.py37
2 files changed, 65 insertions, 74 deletions
diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py
index 7b0fa20c..3a93c7db 100755
--- a/indoteknik_custom/models/purchase_order.py
+++ b/indoteknik_custom/models/purchase_order.py
@@ -61,6 +61,51 @@ class PurchaseOrder(models.Model):
is_create_uangmuka = fields.Boolean(string='Uang Muka?')
move_id = fields.Many2one('account.move', string='Account Move')
+ def _prepare_invoice(self):
+ """Prepare the dict of values to create the new invoice for a purchase order.
+ """
+ self.ensure_one()
+ move_type = self._context.get('default_move_type', 'in_invoice')
+ journal = self.env['account.move'].with_context(default_move_type=move_type)._get_default_journal()
+ if not journal:
+ raise UserError(_('Please define an accounting purchase journal for the company %s (%s).') % (self.company_id.name, self.company_id.id))
+
+
+ date_done = self.picking_ids[0].date_done
+
+ day_extension = int(self.payment_term_id.line_ids.days)
+ payment_schedule = date_done + timedelta(days=day_extension)
+ # Menyesuaikan tanggal sesuai aturan yang diberikan
+ if payment_schedule.weekday() == 0: # 0 adalah indeks untuk hari Senin
+ payment_schedule -= timedelta(days=4) # Mundur ke hari Kamis
+ elif payment_schedule.weekday() == 2: # 2 adalah indeks untuk hari Rabu
+ payment_schedule -= timedelta(days=1) # Mundur ke hari Selasa
+ elif payment_schedule.weekday() == 4: # 4 adalah indeks untuk hari Jumat
+ payment_schedule -= timedelta(days=1) # Mundur ke hari Kamis
+ elif payment_schedule.weekday() == 5: # 5 adalah indeks untuk hari Sabtu
+ payment_schedule -= timedelta(days=2) # Mundur ke hari Kamis
+ elif payment_schedule.weekday() == 6: # 6 adalah indeks untuk hari Minggu
+ payment_schedule -= timedelta(days=3) # Mundur ke hari Kamis
+
+ partner_invoice_id = self.partner_id.address_get(['invoice'])['invoice']
+ invoice_vals = {
+ 'ref': self.partner_ref or '',
+ 'move_type': move_type,
+ 'narration': self.notes,
+ 'currency_id': self.currency_id.id,
+ 'invoice_user_id': self.user_id and self.user_id.id or self.env.user.id,
+ 'partner_id': partner_invoice_id,
+ 'fiscal_position_id': (self.fiscal_position_id or self.fiscal_position_id.get_fiscal_position(partner_invoice_id)).id,
+ 'payment_reference': self.partner_ref or '',
+ 'partner_bank_id': self.partner_id.bank_ids[:1].id,
+ 'invoice_origin': self.name,
+ 'invoice_payment_term_id': self.payment_term_id.id,
+ 'invoice_line_ids': [],
+ 'company_id': self.company_id.id,
+ 'payment_schedule': payment_schedule
+ }
+ return invoice_vals
+
def _compute_matches_so(self):
for po in self:
matches = []
@@ -589,63 +634,6 @@ class PurchaseOrder(models.Model):
self.total_so_margin = 0
self.total_so_percent_margin = 0
- # def compute_total_margin_from_apo(self):
- # purchase_price_dict = {}
-
-
- # for line in self.order_sales_match_line:
- # for lines in self.order_line:
- # product_id = lines.product_id.id
-
- # if product_id not in purchase_price_dict:
- # purchase_price_dict[product_id] = lines.price_subtotal
-
- # sum_so_margin = sum_sales_price = sum_margin = 0
- # sale_order_line = line.sale_line_id
-
- # if not sale_order_line:
- # sale_order_line = self.env['sale.order.line'].search([
- # ('product_id', '=', line.product_id.id),
- # ('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 * 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
-
- # if sale_order_line.order_id.fee_third_party > 0:
- # sales_price -= sale_order_line.fee_third_party_line
-
- # sum_sales_price += sales_price
-
- # product_id = sale_order_line.product_id.id
-
- # purchase_price = purchase_price_dict.get(product_id, 0)
- # # purchase_price = lines.price_subtotal
- # if lines.order_id.delivery_amount > 0:
- # purchase_price += lines.delivery_amt_line
-
- # if line.purchase_order_id.delivery_amount > 0:
- # purchase_price += 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
-
def compute_amt_total_without_service(self):
for order in self:
sum_price_total = 0
diff --git a/indoteknik_custom/models/report_stock_forecasted.py b/indoteknik_custom/models/report_stock_forecasted.py
index 92da13d5..8e92a9b8 100644
--- a/indoteknik_custom/models/report_stock_forecasted.py
+++ b/indoteknik_custom/models/report_stock_forecasted.py
@@ -10,28 +10,31 @@ class ReplenishmentReport(models.AbstractModel):
for line in lines:
document_out = line.get('document_out')
- order_id = document_out.id if document_out else None
- product_id = line.get('product', {}).get('id')
- query = [('product_id', '=', product_id)]
- if order_id:
- result = self._calculate_result(line)
- quantity = line.get('quantity', 0)
- result_dict.setdefault(order_id, []).append((result, quantity))
+ if "SO/" in document_out.name:
+ document_out = line.get('document_out')
+ order_id = document_out.id if document_out else None
+ product_id = line.get('product', {}).get('id')
+ query = [('product_id', '=', product_id)]
- for order_id, results in result_dict.items():
- sales_order = self.env['sale.order'].browse(order_id)
+ if order_id:
+ result = self._calculate_result(line)
+ quantity = line.get('quantity', 0)
+ result_dict.setdefault(order_id, []).append((result, quantity))
- for result, quantity in results:
- self.env['sales.order.fullfillment'].create({
- 'sales_order_id': sales_order.id,
- 'product_id': product_id,
- 'reserved_from': result,
- 'qty_fullfillment': quantity,
- })
+ for order_id, results in result_dict.items():
+ sales_order = self.env['sale.order'].browse(order_id)
+ for result, quantity in results:
+ self.env['sales.order.fullfillment'].create({
+ 'sales_order_id': sales_order.id,
+ 'product_id': product_id,
+ 'reserved_from': result,
+ 'qty_fullfillment': quantity,
+ })
- return lines
+
+ return lines
def _calculate_result(self, line):
if line['document_in']: