summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/purchase_order.py
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2024-07-02 10:06:29 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2024-07-02 10:06:29 +0700
commita10024fec206f68791c87a5a4e56e4c6bce28f5c (patch)
tree627d0ca2443eecbcb44b1b4eeda98f94c9ea3496 /indoteknik_custom/models/purchase_order.py
parent51c19eca13239fe20ae592f8e9ee0d23f8904c5f (diff)
parentf9c5b3dffcd71bfa9dea74c946d7b4277db66bd6 (diff)
Merge branch 'production' into feature/add_voucher_pastihemat_productsolr
Diffstat (limited to 'indoteknik_custom/models/purchase_order.py')
-rwxr-xr-xindoteknik_custom/models/purchase_order.py117
1 files changed, 60 insertions, 57 deletions
diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py
index 7b0fa20c..4a029441 100755
--- a/indoteknik_custom/models/purchase_order.py
+++ b/indoteknik_custom/models/purchase_order.py
@@ -60,6 +60,60 @@ class PurchaseOrder(models.Model):
matches_so = fields.Many2many('sale.order', string='Matches SO', compute='_compute_matches_so')
is_create_uangmuka = fields.Boolean(string='Uang Muka?')
move_id = fields.Many2one('account.move', string='Account Move')
+ logbook_bill_id = fields.Many2one('report.logbook.bill', string='Logbook Bill')
+ status_printed = fields.Selection([
+ ('not_printed', 'Belum Print'),
+ ('printed', 'Printed')
+ ], string='Printed?', copy=False, tracking=True)
+
+ 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))
+
+ stock_picking = self.env['stock.picking'].search([
+ ('purchase_id', '=', self.id),
+ ('state', '=', 'done')
+ ], order='date_done desc', limit=1)
+
+ date_done = stock_picking.date_done
+
+ day_extension = int(self.payment_term_id.line_ids.days)
+ payment_schedule = date_done + timedelta(days=day_extension)
+
+ if payment_schedule.weekday() == 0:
+ payment_schedule -= timedelta(days=4)
+ elif payment_schedule.weekday() == 2:
+ payment_schedule -= timedelta(days=1)
+ elif payment_schedule.weekday() == 4:
+ payment_schedule -= timedelta(days=1)
+ elif payment_schedule.weekday() == 5:
+ payment_schedule -= timedelta(days=2)
+ elif payment_schedule.weekday() == 6:
+ payment_schedule -= timedelta(days=3)
+
+ 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:
@@ -389,6 +443,12 @@ class PurchaseOrder(models.Model):
for line in self.order_line:
if not line.product_id.purchase_ok:
raise UserError("Terdapat barang yang tidak bisa diproses")
+ # Validasi pajak
+ if not line.taxes_id:
+ raise UserError("Masukkan Tax untuk produk")
+ for tax in line.taxes_id:
+ if tax.type_tax_use != 'purchase':
+ raise UserError("Pastikan Tax Category nya adalah Purchase pada produk %s" % line.product_id.name)
if line.price_unit != line.price_vendor and line.price_vendor != 0:
self._send_po_not_sync()
send_email = True
@@ -589,63 +649,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