diff options
| author | Azka Nathan <darizkyfaz@gmail.com> | 2024-02-07 10:45:51 +0700 |
|---|---|---|
| committer | Azka Nathan <darizkyfaz@gmail.com> | 2024-02-07 10:45:51 +0700 |
| commit | f6be42d37a363b86f4a9ec71ccb38c78cbe2d887 (patch) | |
| tree | 9c297e776f67e35671012e94d3c64007bd5090d7 /indoteknik_custom/models/purchase_order_line.py | |
| parent | edb3c1c80931078d40a8f56149aeca9efdcdc07d (diff) | |
| parent | 29a9ec94f1ad131f398cf119a03a7b927a4c6cba (diff) | |
Merge branch 'production' into purchasing-job
# Conflicts:
# indoteknik_custom/__manifest__.py
# indoteknik_custom/models/__init__.py
# indoteknik_custom/models/automatic_purchase.py
# indoteknik_custom/models/purchase_order_line.py
# indoteknik_custom/security/ir.model.access.csv
# indoteknik_custom/views/automatic_purchase.xml
# indoteknik_custom/views/purchase_order.xml
Diffstat (limited to 'indoteknik_custom/models/purchase_order_line.py')
| -rwxr-xr-x | indoteknik_custom/models/purchase_order_line.py | 67 |
1 files changed, 63 insertions, 4 deletions
diff --git a/indoteknik_custom/models/purchase_order_line.py b/indoteknik_custom/models/purchase_order_line.py index 8d7d818b..c2e7a4c7 100755 --- a/indoteknik_custom/models/purchase_order_line.py +++ b/indoteknik_custom/models/purchase_order_line.py @@ -2,6 +2,7 @@ from odoo import fields, models, api, _ from odoo.exceptions import AccessError, UserError, ValidationError from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT import logging +from datetime import datetime _logger = logging.getLogger(__name__) @@ -35,6 +36,46 @@ class PurchaseOrderLine(models.Model): note = fields.Char(string='Note') sale_automatic_id = fields.Many2one('sale.order', string='SO') + qty_reserved = fields.Float(string='Qty Reserved', compute='_compute_qty_reserved') + delete_line = fields.Boolean(string='Delete', default=False, help='centang ini jika anda ingin menghapus line ini') + is_edit_product_qty = fields.Boolean(string='Is Edit Product Qty', compute='_compute_is_edit_product_qty') + + def _compute_is_edit_product_qty(self): + for line in self: + + if line.order_id.state in ['draft']: + is_valid = True + else: + is_valid = False + + line.is_edit_product_qty = is_valid + + # @api.constrains('product_qty') + # def change_qty_po_and_qty_demand(self): + # for line in self: + # if line.order_id.state in ['draft', 'cancel'] and len(line.order_id.picking_ids) == 0: + # continue + + # for stock_picking in line.order_id.picking_ids: + # picking = self.env['stock.move'].search([ + # ('picking_id.purchase_id', '=', line.order_id.id), + # ('product_id', '=', line.product_id.id) + # ]) + + # if picking: + # picking.write({ + # 'product_uom_qty': line.product_qty + # }) + + def _compute_qty_reserved(self): + for line in self: + sale_line = self.env['sale.order.line'].search([ + ('product_id', '=', line.product_id.id), + ('order_id', '=', line.order_id.sale_order_id.id) + ]) + + reserved_qty = sum(line.qty_reserved for line in sale_line) + line.qty_reserved = reserved_qty # so_line.qty_reserved (compute) # so_line.qty_reserved = get from picking_ids where type outgoing and prodid = line.prodid @@ -73,14 +114,12 @@ class PurchaseOrderLine(models.Model): def _onchange_product_custom(self): self._compute_qty_stock() - # Override method from addons/purchase/models/purchase.py - @api.onchange('product_qty', 'product_uom') + @api.onchange('product_id','product_qty', 'product_uom') def _onchange_quantity(self): res = super(PurchaseOrderLine, self)._onchange_quantity() - # Custom script purchase_pricelist = self.env['purchase.pricelist'].search([ ('product_id', '=', self.product_id.id), - ('vendor_id', '=', self.partner_id.id) + ('vendor_id', '=', self.partner_id.id), ], limit=1) price_unit = purchase_pricelist.product_price @@ -91,8 +130,28 @@ class PurchaseOrderLine(models.Model): ], limit=1) price_unit = product_supplierinfo.price + price_unit, taxes = self._get_valid_purchase_price(purchase_pricelist) + self.price_unit = price_unit + if purchase_pricelist.taxes_product_id or purchase_pricelist.taxes_system_id: + self.taxes_id = taxes + return res + + def _get_valid_purchase_price(self, purchase_price): + price = 0 + taxes = None + human_last_update = purchase_price.human_last_update or datetime.min + system_last_update = purchase_price.system_last_update or datetime.min + + if system_last_update > human_last_update: + price = purchase_price.system_price + taxes = [purchase.taxes_system_id.id for purchase in purchase_price ] + else: + price = purchase_price.product_price + taxes = [purchase.taxes_product_id.id for purchase in purchase_price ] + + return price, taxes def compute_item_margin(self): sum_so_margin = sum_sales_price = sum_margin = 0 |
