summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/purchase_order.py
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2024-09-12 10:35:01 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2024-09-12 10:35:01 +0700
commit16acaa437f203ccfa52aba132225b2bb82ac1c79 (patch)
treed4ce062668f1f6d2642e5280f979e60d0acf05a0 /indoteknik_custom/models/purchase_order.py
parentf03e6dc2ee2f3cd34eca15e81cd8964c07089ef4 (diff)
parenta8e539c92236453ce7aad06d23cf117f4b7239fc (diff)
Merge branch 'production' into unreserved_permission
# Conflicts: # indoteknik_api/controllers/api_v1/cart.py # indoteknik_custom/models/sale_order.py
Diffstat (limited to 'indoteknik_custom/models/purchase_order.py')
-rwxr-xr-xindoteknik_custom/models/purchase_order.py60
1 files changed, 60 insertions, 0 deletions
diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py
index 8ec904a9..edcbbb19 100755
--- a/indoteknik_custom/models/purchase_order.py
+++ b/indoteknik_custom/models/purchase_order.py
@@ -31,6 +31,7 @@ class PurchaseOrder(models.Model):
('approved', 'Approved'),
], string='Approval Status', readonly=True, copy=False, index=True, tracking=3)
delivery_amount = fields.Float('Delivery Amount', compute='compute_delivery_amount')
+ delivery_amt = fields.Float('Delivery Amt')
total_margin = fields.Float(
'Margin', compute='compute_total_margin',
help="Total Margin in Sales Order Header")
@@ -66,6 +67,61 @@ class PurchaseOrder(models.Model):
('printed', 'Printed')
], 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')
+ grand_total = fields.Monetary(string='Grand Total', help='Amount total + amount delivery', compute='_compute_grand_total')
+
+ def _compute_grand_total(self):
+ for order in self:
+ if order.delivery_amt:
+ order.grand_total = order.delivery_amt + order.amount_total
+ else:
+ order.grand_total = order.amount_total
+
+ def create_bill_dp(self):
+ if not self.env.user.is_accounting:
+ raise UserError('Hanya Accounting yang bisa bikin bill dp')
+
+ 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 = {
+ 'move_id': bills.id,
+ 'product_id': product_dp.id, #product down payment
+ 'account_id': 401, #Uang Muka persediaan barang dagang
+ 'quantity': 1,
+ 'product_uom_id': 1,
+ 'tax_ids': [line[0].taxes_id.id for line in self.order_line],
+ }
+
+
+ bills_line = self.env['account.move.line'].create([data_line_bills])
+
+ self.bills_dp_id = bills.id
+
+ move_line = bills.line_ids
+ move_line.name = '[IT.121456] Down Payment'
+ move_line.partner_id = self.partner_id.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 get_date_done(self):
picking = self.env['stock.picking'].search([
@@ -624,6 +680,8 @@ class PurchaseOrder(models.Model):
purchase_price = line.price_subtotal
if line.order_id.delivery_amount > 0:
purchase_price += line.delivery_amt_line
+ if line.order_id.delivery_amt > 0:
+ purchase_price += line.order_id.delivery_amt
real_item_margin = sales_price - purchase_price
sum_margin += real_item_margin
@@ -666,6 +724,8 @@ class PurchaseOrder(models.Model):
purchase_price = po_line.price_subtotal / po_line.product_qty * line.qty_po
if line.purchase_order_id.delivery_amount > 0:
purchase_price += (po_line.delivery_amt_line / po_line.product_qty) * line.qty_po
+ if line.purchase_order_id.delivery_amt > 0:
+ purchase_price += line.purchase_order_id.delivery_amt
real_item_margin = sales_price - purchase_price
sum_margin += real_item_margin