summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/purchase_order.py
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2024-10-25 14:00:02 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2024-10-25 14:00:02 +0700
commitbf6db57611262036be96e2f7cc93e315b208f174 (patch)
tree6bd3c63d692dfbd9b9426a5a230d40b4c6117034 /indoteknik_custom/models/purchase_order.py
parent039bbc5e941b06199b6c44bb8898a4121e312355 (diff)
bills pelunasan
Diffstat (limited to 'indoteknik_custom/models/purchase_order.py')
-rwxr-xr-xindoteknik_custom/models/purchase_order.py70
1 files changed, 70 insertions, 0 deletions
diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py
index f924174a..c24bdbb3 100755
--- a/indoteknik_custom/models/purchase_order.py
+++ b/indoteknik_custom/models/purchase_order.py
@@ -68,6 +68,7 @@ class PurchaseOrder(models.Model):
], string='Printed?', copy=False, tracking=True)
date_done_picking = fields.Datetime(string='Date Done Picking', compute='get_date_done')
bills_dp_id = fields.Many2one('account.move', string='Bills DP')
+ bills_pelunasan_id = fields.Many2one('account.move', string='Bills Pelunasan')
grand_total = fields.Monetary(string='Grand Total', help='Amount total + amount delivery', compute='_compute_grand_total')
total_margin_match = fields.Float(string='Total Margin Match', compute='_compute_total_margin_match')
approve_by = fields.Many2one('res.users', string='Approve By')
@@ -89,6 +90,75 @@ class PurchaseOrder(models.Model):
else:
order.grand_total = order.amount_total
+ def create_bill_pelunasan(self):
+ if not self.env.user.is_accounting:
+ raise UserError('Hanya Accounting yang bisa bikin bill dp')
+
+ # Check for existing vendor bills with the same reference and partner
+ existing_bill = self.env['account.move'].search([
+ ('ref', '=', self.name),
+ ('partner_id', '=', self.partner_id.id),
+ ('move_type', '=', 'in_invoice'),
+ ('state', 'not in', ['cancel', 'posted'])
+ ], limit=1)
+
+ if existing_bill:
+ raise UserError(_('Duplicated vendor reference detected. You probably encoded twice the same vendor bill/credit note: %s') % existing_bill.name)
+
+ current_date = datetime.utcnow()
+ data_bills = {
+ 'partner_id': self.partner_id.id,
+ 'partner_shipping_id': self.partner_id.id,
+ 'ref': self.name,
+ 'invoice_date': current_date,
+ 'date': current_date,
+ 'move_type': 'in_invoice'
+ }
+
+ bills = self.env['account.move'].create([data_bills])
+
+ product_dp = self.env['product.product'].browse(229625)
+
+ data_line_bills = []
+
+ data_line_bills.append({
+ 'move_id': bills.id,
+ 'product_id': product_dp.id, # product down payment
+ 'name': '[IT.121456] Down Payment', # product down payment
+ 'account_id': 401, # Uang Muka persediaan barang dagang
+ 'quantity': -1,
+ 'product_uom_id': 1,
+ 'tax_ids': [(5, 0, 0)] + [(4, tax.id) for tax in product_dp.taxes_id],
+ })
+
+ for line in self.order_line:
+ if line.product_id:
+ data_line_bills.append({
+ 'move_id': bills.id,
+ 'product_id': line.product_id.id,
+ 'name': self.name + ": " + line.product_id.display_name,
+ 'account_id': 439, # Uang Muka persediaan barang dagang
+ 'quantity': line.product_qty,
+ 'price_unit': line.price_unit,
+ 'product_uom_id': line.product_uom.id,
+ 'tax_ids': [(5, 0, 0)] + [(4, tax.id) for tax in line.taxes_id],
+ })
+
+ bills_line = self.env['account.move.line'].create(data_line_bills)
+
+ self.bills_pelunasan_id = bills.id
+
+ return {
+ 'name': _('Account Move'),
+ 'view_mode': 'tree,form',
+ 'res_model': 'account.move',
+ 'target': 'current',
+ 'type': 'ir.actions.act_window',
+ 'domain': [('id', '=', bills.id)]
+ }
+
+
+
def create_bill_dp(self):
if not self.env.user.is_accounting:
raise UserError('Hanya Accounting yang bisa bikin bill dp')