diff options
| author | Azka Nathan <darizkyfaz@gmail.com> | 2024-05-10 14:43:15 +0700 |
|---|---|---|
| committer | Azka Nathan <darizkyfaz@gmail.com> | 2024-05-10 14:43:15 +0700 |
| commit | 844339e517540826f6990456a63945dc879e37d5 (patch) | |
| tree | a635964dbd0b9729c1d161e16ca7e8dabb02a3c8 | |
| parent | 1c0c7be74b11371299bead2626840b3ebc2632f7 (diff) | |
| parent | cb9ae6021dd4858372ed78d16ab491226c95f1d2 (diff) | |
Merge branch 'production' into dev/request-by-abl
# Conflicts:
# indoteknik_custom/models/res_partner.py
| -rw-r--r-- | indoteknik_custom/models/automatic_purchase.py | 18 | ||||
| -rwxr-xr-x | indoteknik_custom/models/product_template.py | 2 | ||||
| -rwxr-xr-x | indoteknik_custom/models/purchase_order.py | 29 | ||||
| -rwxr-xr-x | indoteknik_custom/models/purchase_order_line.py | 42 | ||||
| -rw-r--r-- | indoteknik_custom/models/purchasing_job.py | 2 | ||||
| -rw-r--r-- | indoteknik_custom/models/res_partner.py | 6 | ||||
| -rwxr-xr-x | indoteknik_custom/models/sale_order.py | 8 | ||||
| -rw-r--r-- | indoteknik_custom/models/sale_order_line.py | 31 | ||||
| -rw-r--r-- | indoteknik_custom/models/stock_move.py | 1 | ||||
| -rw-r--r-- | indoteknik_custom/models/stock_picking.py | 3 | ||||
| -rwxr-xr-x | indoteknik_custom/views/purchase_order.xml | 4 | ||||
| -rw-r--r-- | indoteknik_custom/views/res_partner.xml | 1 | ||||
| -rwxr-xr-x | indoteknik_custom/views/sale_order.xml | 4 | ||||
| -rw-r--r-- | indoteknik_custom/views/stock_picking.xml | 4 |
14 files changed, 121 insertions, 34 deletions
diff --git a/indoteknik_custom/models/automatic_purchase.py b/indoteknik_custom/models/automatic_purchase.py index dae1c6a4..af09abf0 100644 --- a/indoteknik_custom/models/automatic_purchase.py +++ b/indoteknik_custom/models/automatic_purchase.py @@ -183,8 +183,10 @@ class AutomaticPurchase(models.Model): def create_po_by_vendor(self, vendor_id): current_time = datetime.now() - # if not self.apo_type =='reordering': - # self.check_qty_po() + if not self.apo_type =='reordering': + name = "/PJ/" + else: + name = "/A/" PRODUCT_PER_PO = 20 @@ -218,7 +220,7 @@ class AutomaticPurchase(models.Model): # i start from zero (0) for i in range(page): new_po = self.env['purchase.order'].create([param_header]) - new_po.name = new_po.name + "/PJ/" + str(i + 1) + new_po.name = new_po.name + name + str(i + 1) self.env['automatic.purchase.match'].create([{ 'automatic_purchase_id': self.id, @@ -253,7 +255,8 @@ class AutomaticPurchase(models.Model): 'product_uom_qty': line.qty_purchase, 'price_unit': line.last_price, 'taxes_id': [line.taxes_id.id] if line.taxes_id else None, - # 'so_line_id': [sales.sale_line_id.id for sales in sales_match], + 'so_line_id': sales_match[0].sale_line_id.id if sales_match else None, + 'so_id': sales_match[0].sale_id.id if sales_match else None } new_po_line = self.env['purchase.order.line'].create([param_line]) line.current_po_id = new_po.id @@ -279,7 +282,10 @@ class AutomaticPurchase(models.Model): ('sale_line_id.product_id', 'in', matches_so_product_ids), ]) + sale_ids_set = set() for sale_order in matches_so: + sale_ids_set.add(str(sale_order.sale_id.name)) + matches_so_line = { 'purchase_order_id': purchase_order.id, 'sale_id': sale_order.sale_id.id, @@ -295,6 +301,10 @@ class AutomaticPurchase(models.Model): 'margin_so': sale_order.sale_line_id.item_percent_margin } po_matches_so_line = self.env['purchase.order.sales.match'].create([matches_so_line]) + + sale_ids_str = ','.join(sale_ids_set) + + purchase_order.sale_order = sale_ids_str self.create_sales_order_purchase_match(purchase_order) diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py index 4bab2cad..8494e18a 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -410,7 +410,7 @@ class ProductProduct(models.Model): for product in self: qty_onhand = self.env['stock.quant'].search([ ('product_id', '=', product.id), - ('location_id', '=', 57) + ('location_id', 'in', [57, 83]) ]) qty = sum(qty_onhand.mapped('quantity')) product.qty_onhand_bandengan = qty diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index caad90d3..5946399d 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -1,5 +1,6 @@ from odoo import fields, models, api, _ from odoo.exceptions import AccessError, UserError, ValidationError +from dateutil.relativedelta import relativedelta from datetime import datetime, timedelta import logging from pytz import timezone, utc @@ -55,6 +56,33 @@ class PurchaseOrder(models.Model): revisi_po = fields.Boolean(string='Revisi', tracking=3) from_apo = fields.Boolean(string='From APO', tracking=3) approval_edit_line = fields.Boolean(string='Approval Edit Line', tracking=3) + sale_order = fields.Char(string='Sale Order') + + def _prepare_picking(self): + if not self.group_id: + self.group_id = self.group_id.create({ + 'name': self.name, + 'partner_id': self.partner_id.id + }) + + if self.sale_order_id: + sale_order = self.sale_order_id + else: + sale_order = self.sale_order + + if not self.partner_id.property_stock_supplier.id: + raise UserError(_("You must set a Vendor Location for this partner %s", self.partner_id.name)) + return { + 'picking_type_id': self.picking_type_id.id, + 'partner_id': self.partner_id.id, + 'user_id': False, + 'date': self.date_order, + 'origin': self.name, + 'location_dest_id': self._get_destination_location(), + 'location_id': self.partner_id.property_stock_supplier.id, + 'company_id': self.company_id.id, + 'sale_order': sale_order, + } @api.model def action_multi_cancel(self): @@ -288,6 +316,7 @@ class PurchaseOrder(models.Model): 'qty_available_store': qty_available, # 'suggest': suggest, 'so_line_id': order_line.id, + 'so_id': order_line.order_id.id, } self.order_line.create(values) for order_line in self.order_line: diff --git a/indoteknik_custom/models/purchase_order_line.py b/indoteknik_custom/models/purchase_order_line.py index 2eeb7d3e..8a3b3930 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 dateutil.relativedelta import relativedelta from datetime import datetime _logger = logging.getLogger(__name__) @@ -31,6 +32,7 @@ class PurchaseOrderLine(models.Model): suggest = fields.Char(string='Suggest') price_vendor = fields.Float(string='Price Vendor', compute='compute_price_vendor') so_line_id = fields.Many2one('sale.order.line', string='ID SO Line') + so_id = fields.Many2one('sale.order', string='SO') indent = fields.Boolean(string='Indent', help='centang ini jika barang indent') is_ltc = fields.Boolean(string='Sudah di LTC', default=False, help='centang ini jika barang sudah di LTC') note = fields.Char(string='Note') @@ -40,6 +42,46 @@ class PurchaseOrderLine(models.Model): 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 _prepare_stock_move_vals(self, picking, price_unit, product_uom_qty, product_uom): + self.ensure_one() + product = self.product_id.with_context(lang=self.order_id.dest_address_id.lang or self.env.user.lang) + description_picking = product._get_description(self.order_id.picking_type_id) + if self.product_description_variants: + description_picking += "\n" + self.product_description_variants + date_planned = self.date_planned or self.order_id.date_planned + + if self.so_id: + sale_id = self.so_id.id + else: + sale_id = self.so_line_id.order_id.id + + return { + # truncate to 2000 to avoid triggering index limit error + # TODO: remove index in master? + 'name': (self.name or '')[:2000], + 'product_id': self.product_id.id, + 'date': date_planned, + 'date_deadline': date_planned + relativedelta(days=self.order_id.company_id.po_lead), + 'location_id': self.order_id.partner_id.property_stock_supplier.id, + 'location_dest_id': (self.orderpoint_id and not (self.move_ids | self.move_dest_ids)) and self.orderpoint_id.location_id.id or self.order_id._get_destination_location(), + 'picking_id': picking.id, + 'partner_id': self.order_id.dest_address_id.id, + 'move_dest_ids': [(4, x) for x in self.move_dest_ids.ids], + 'state': 'draft', + 'purchase_line_id': self.id, + 'company_id': self.order_id.company_id.id, + 'price_unit': price_unit, + 'picking_type_id': self.order_id.picking_type_id.id, + 'group_id': self.order_id.group_id.id, + 'origin': self.order_id.name, + 'description_picking': description_picking, + 'propagate_cancel': self.propagate_cancel, + 'warehouse_id': self.order_id.picking_type_id.warehouse_id.id, + 'product_uom_qty': product_uom_qty, + 'product_uom': product_uom.id, + 'sale_id': sale_id, + } + @api.constrains('price_unit') def constrains_purchase_price(self): for line in self: diff --git a/indoteknik_custom/models/purchasing_job.py b/indoteknik_custom/models/purchasing_job.py index deec88d7..86f8afcc 100644 --- a/indoteknik_custom/models/purchasing_job.py +++ b/indoteknik_custom/models/purchasing_job.py @@ -58,6 +58,8 @@ class PurchasingJob(models.Model): CASE WHEN vendor_id = 5571 THEN 27 WHEN vendor_id = 9688 THEN 397 + WHEN vendor_id = 35475 THEN 397 + WHEN vendor_id = 29712 THEN 397 ELSE (CASE WHEN random() < 0.5 THEN 397 ELSE 1036 END) END AS user_id, vendor_id diff --git a/indoteknik_custom/models/res_partner.py b/indoteknik_custom/models/res_partner.py index bc8e2b0d..eee19b2f 100644 --- a/indoteknik_custom/models/res_partner.py +++ b/indoteknik_custom/models/res_partner.py @@ -33,6 +33,12 @@ class ResPartner(models.Model): ], string='Web Role') site_id = fields.Many2one('res.partner.site', string='Site') main_parent_id = fields.Many2one('res.partner', string='Main Parent', compute='_compute_main_parent_id') + pareto_status = fields.Selection([ + ('PR', 'Pareto Repeating'), + ('PPR', 'Potensi Pareto Repeating'), + ('PNR', 'Pareto Non Repeating'), + ('NP', 'Non Pareto') + ]) @api.onchange('site_id') def _onchange_site_id(self): diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 055b545a..aa34b0f4 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -100,14 +100,14 @@ class SaleOrder(models.Model): def _compute_fullfillment(self): for rec in self: - for fullfillment in rec.fullfillment_line: - fullfillment.unlink() - + rec.fullfillment_line.unlink() + for line in rec.order_line: line._compute_reserved_from() - + rec.compute_fullfillment = True + def _compute_eta_date(self): max_leadtime = 0 diff --git a/indoteknik_custom/models/sale_order_line.py b/indoteknik_custom/models/sale_order_line.py index 39366028..8fb34328 100644 --- a/indoteknik_custom/models/sale_order_line.py +++ b/indoteknik_custom/models/sale_order_line.py @@ -31,30 +31,13 @@ class SaleOrderLine(models.Model): qty_reserved = fields.Float(string='Qty Reserved', compute='_compute_qty_reserved') reserved_from = fields.Char(string='Reserved From', copy=False) - # def get_reserved_from(self): - # for line in self: - # current_stock = self.env['stock.quant'].search([ - # ('product_id', '=', line.product_id.id), - # ('location_id', '=', line.order_id.warehouse_id.lot_stock_id.id) - # ]) - - # po_stock = self.env['purchase.order.line'].search([ - # ('product_id', '=', line.product_id.id), - # ('order_id.sale_order_id', '=', line.order_id.id), - # ('state', '=', 'done') - # ]) - - # available_quantity = current_stock.available_quantity if current_stock else 0 - # product_qty = po_stock.product_qty if po_stock else 0 - - # if available_quantity >= line.product_uom_qty: - # line.reserved_from = 'From Stock' - # elif product_qty >= line.product_uom_qty: - # line.reserved_from = 'From PO' - # elif (available_quantity + product_qty) >= line.product_uom_qty: - # line.reserved_from = 'From Stock and PO' - # else: - # line.reserved_from = None + @api.onchange('product_uom', 'product_uom_qty') + def product_uom_change(self): + if not self.product_uom or not self.product_id: + self.price_unit = 0.0 + return + + self.price_unit = self.price_unit def _compute_qty_reserved(self): for line in self: diff --git a/indoteknik_custom/models/stock_move.py b/indoteknik_custom/models/stock_move.py index dade9a04..9c991be3 100644 --- a/indoteknik_custom/models/stock_move.py +++ b/indoteknik_custom/models/stock_move.py @@ -5,6 +5,7 @@ class StockMove(models.Model): _inherit = 'stock.move' line_no = fields.Integer('No', default=0) + sale_id = fields.Many2one('sale.order', string='SO') def _prepare_account_move_line_from_mr(self, po_line, qty, move=False): po_line.ensure_one() diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py index c2508660..9b4fffb1 100644 --- a/indoteknik_custom/models/stock_picking.py +++ b/indoteknik_custom/models/stock_picking.py @@ -81,9 +81,10 @@ class StockPicking(models.Model): status_printed = fields.Selection([ ('not_printed', 'Belum Print'), ('printed', 'Printed') - ], string='Printed?', copy=False) + ], string='Printed?', copy=False, tracking=True) date_unreserve = fields.Datetime(string="Date Unreserved", copy=False, tracking=True) date_availability = fields.Datetime(string="Date Availability", copy=False, tracking=True) + sale_order = fields.Char(string='Matches SO', copy=False) def do_unreserve(self): res = super(StockPicking, self).do_unreserve() diff --git a/indoteknik_custom/views/purchase_order.xml b/indoteknik_custom/views/purchase_order.xml index 33603216..bb38715e 100755 --- a/indoteknik_custom/views/purchase_order.xml +++ b/indoteknik_custom/views/purchase_order.xml @@ -28,6 +28,7 @@ </button> <field name="date_order" position="before"> <field name="sale_order_id" attrs="{'readonly': [('state', 'not in', ['draft'])]}"/> + <field name="sale_order"/> <field name="approval_status"/> <field name="amount_total_without_service"/> </field> @@ -71,6 +72,7 @@ </field> <field name="price_subtotal" position="after"> <field name="so_line_id" attrs="{'readonly': 1}" optional="hide"/> + <field name="so_id" attrs="{'readonly': 1}" optional="hide"/> <field name="indent" optional="hide"/> </field> <page name="purchase_delivery_invoice" position="after"> @@ -158,6 +160,7 @@ <field name="arch" type="xml"> <field name="name" position="after"> <field name="sale_order_id" string="Sale Order"/> + <field name="sale_order" string="Matches Sale Order"/> </field> </field> </record> @@ -170,6 +173,7 @@ <field name="arch" type="xml"> <field name="name" position="after"> <field name="sale_order_id" string="Sale Order"/> + <field name="sale_order" string="Matches Sale Order"/> </field> </field> </record> diff --git a/indoteknik_custom/views/res_partner.xml b/indoteknik_custom/views/res_partner.xml index f79b684e..59d33f29 100644 --- a/indoteknik_custom/views/res_partner.xml +++ b/indoteknik_custom/views/res_partner.xml @@ -15,6 +15,7 @@ <field name="company_type_id"/> <field name="group_partner_id"/> <field name="is_potential"/> + <field name="pareto_status"/> <field name="digital_invoice_tax"/> </field> <field name="npwp" position="before"> diff --git a/indoteknik_custom/views/sale_order.xml b/indoteknik_custom/views/sale_order.xml index 77740dd0..d6738759 100755 --- a/indoteknik_custom/views/sale_order.xml +++ b/indoteknik_custom/views/sale_order.xml @@ -49,6 +49,7 @@ </field> <field name="user_id" position="after"> <field name="helper_by_id" readonly="1"/> + <field name="compute_fullfillment"/> </field> <field name="tag_ids" position="after"> <field name="eta_date" readonly="1"/> @@ -186,6 +187,9 @@ <page string="Matches PO" name="page_matches_po" invisible="1"> <field name="order_sales_match_line" readonly="1"/> </page> + <page string="Fullfillment" name="page_sale_order_fullfillment"> + <field name="fullfillment_line" readonly="1"/> + </page> </page> </field> </record> diff --git a/indoteknik_custom/views/stock_picking.xml b/indoteknik_custom/views/stock_picking.xml index a8772906..90f662cc 100644 --- a/indoteknik_custom/views/stock_picking.xml +++ b/indoteknik_custom/views/stock_picking.xml @@ -61,6 +61,7 @@ <field name="origin" position="after"> <field name="status_printed"/> <field name="purchase_id"/> + <field name="sale_order"/> <field name="date_doc_kirim"/> <field name="summary_qty_operation"/> <field name="count_line_operation"/> @@ -87,6 +88,9 @@ <field name="product_id" position="before"> <field name="line_no" attrs="{'readonly': 1}" optional="hide"/> </field> + <field name="product_uom" position="after"> + <field name="sale_id" attrs="{'readonly': 1}" optional="hide"/> + </field> <page name="note" position="after"> <page string="E-Faktur" name="efaktur" attrs="{'invisible': [['is_internal_use', '=', False]]}"> <group> |
