From a7eda38c3a1146a33da50ae6a6f87cbc61bbfc97 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Wed, 19 Jun 2024 11:53:57 +0700 Subject: change request payment_schedule and fix sales order fulfilment bug --- indoteknik_custom/models/purchase_order.py | 102 +++++++++++++---------------- 1 file changed, 45 insertions(+), 57 deletions(-) (limited to 'indoteknik_custom/models/purchase_order.py') 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 -- cgit v1.2.3 From 69679a78e128f22e0568c2b3e40b61f6065bf785 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 20 Jun 2024 17:01:32 +0700 Subject: fix error while create bill --- indoteknik_custom/models/purchase_order.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'indoteknik_custom/models/purchase_order.py') diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index 3a93c7db..c2a599ca 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -69,9 +69,13 @@ class PurchaseOrder(models.Model): 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 + 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) -- cgit v1.2.3 From ac01fa257abf2f12588d240689c42f0d12da644f Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Tue, 25 Jun 2024 09:09:34 +0700 Subject: trying to fix ppn keluar on bill --- indoteknik_custom/models/purchase_order.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'indoteknik_custom/models/purchase_order.py') diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index c2a599ca..836df945 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -79,17 +79,17 @@ class PurchaseOrder(models.Model): 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 + + 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 = { -- cgit v1.2.3 From fcc629d93b0da863bcdab2fad0812deeee5da6b2 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Wed, 26 Jun 2024 10:23:48 +0700 Subject: add tax validation & product category --- indoteknik_custom/models/purchase_order.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'indoteknik_custom/models/purchase_order.py') diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index 836df945..db474895 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -438,6 +438,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 -- cgit v1.2.3 From e33f2d321ee4db6a6e6a86e35243100b9f107f22 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 27 Jun 2024 15:29:16 +0700 Subject: logbook bill & send email efaktur document --- indoteknik_custom/models/purchase_order.py | 1 + 1 file changed, 1 insertion(+) (limited to 'indoteknik_custom/models/purchase_order.py') diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index db474895..6aec4074 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -60,6 +60,7 @@ 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') def _prepare_invoice(self): """Prepare the dict of values to create the new invoice for a purchase order. -- cgit v1.2.3 From 6b83f1e5a61c2d1f97fb5c0f1c55f0730f83a498 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 27 Jun 2024 15:58:33 +0700 Subject: add flag if po has printed --- indoteknik_custom/models/purchase_order.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'indoteknik_custom/models/purchase_order.py') diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index 6aec4074..4a029441 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -61,6 +61,10 @@ class PurchaseOrder(models.Model): 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. -- cgit v1.2.3