diff options
| author | Rafi Zadanly <zadanlyr@gmail.com> | 2023-10-31 10:39:29 +0700 |
|---|---|---|
| committer | Rafi Zadanly <zadanlyr@gmail.com> | 2023-10-31 10:39:29 +0700 |
| commit | 3cc65898e703c4857908b97bc5ab63c8452be684 (patch) | |
| tree | ac0465f78da9c0efdd4f9acf72aec3d529f6db78 | |
| parent | 0831511787b1cd2171d6dd1dd6c2c9da46b64d2e (diff) | |
| parent | d426ff142df8b5778398e3b460ff03d02d9e368a (diff) | |
Merge branch 'production' into cr/auth
# Conflicts:
# indoteknik_custom/__manifest__.py
18 files changed, 135 insertions, 11 deletions
diff --git a/indoteknik_custom/__manifest__.py b/indoteknik_custom/__manifest__.py index 000c7fe2..ace5c720 100755 --- a/indoteknik_custom/__manifest__.py +++ b/indoteknik_custom/__manifest__.py @@ -100,6 +100,7 @@ 'views/stock_move_line.xml', 'views/product_monitoring.xml', 'views/res_users.xml', + 'views/stock_warehouse_orderpoint.xml', 'report/report.xml', 'report/report_banner_banner.xml', 'report/report_banner_banner2.xml', diff --git a/indoteknik_custom/models/__init__.py b/indoteknik_custom/models/__init__.py index 1133c3e7..6a5eac00 100755 --- a/indoteknik_custom/models/__init__.py +++ b/indoteknik_custom/models/__init__.py @@ -89,4 +89,5 @@ from . import stock_scheduler_compute from . import promotion from . import sale_orders_multi_update from . import quotation_so_multi_update -from . import product_monitoring
\ No newline at end of file +from . import product_monitoring +from . import stock_warehouse_orderpoint diff --git a/indoteknik_custom/models/automatic_purchase.py b/indoteknik_custom/models/automatic_purchase.py index 990d3cc5..f81ecdcc 100644 --- a/indoteknik_custom/models/automatic_purchase.py +++ b/indoteknik_custom/models/automatic_purchase.py @@ -17,6 +17,7 @@ class AutomaticPurchase(models.Model): is_po = fields.Boolean(string='Is PO') purchase_match = fields.One2many('automatic.purchase.match', 'automatic_purchase_id', string='Matches', auto_join=True) vendor_id = fields.Many2one('res.partner', string='Vendor', help='boleh kosong, jika diisi, maka hanya keluar data untuk vendor tersebut') + responsible_id = fields.Many2one('res.users', string='Responsible', required=True) def create_po_from_automatic_purchase(self): if not self.purchase_lines: @@ -87,7 +88,8 @@ class AutomaticPurchase(models.Model): raise UserError('Sudah digenerate sebelumnya, hapus line terlebih dahulu') query = [ - ('product_min_qty', '>', 0) + ('product_min_qty', '>', 0), + ('product_id.x_manufacture.user_id.id', '=', self.responsible_id.id) ] orderpoints = self.env['stock.warehouse.orderpoint'].search(query) count = 0 @@ -101,10 +103,14 @@ class AutomaticPurchase(models.Model): if self.vendor_id: purchase_price = self.env['purchase.pricelist'].search([ ('product_id', '=', point.product_id.id), + # ('product_id.x_manufacture.user_id.id', '=', self.responsible_id.id), ('vendor_id', '=', self.vendor_id.id) ], order='product_price asc', limit=1) else: - purchase_price = self.env['purchase.pricelist'].search([('product_id', '=', point.product_id.id)], order='product_price asc', limit=1) + purchase_price = self.env['purchase.pricelist'].search([ + ('product_id', '=', point.product_id.id), + # ('product_id.x_manufacture.user_id.id', '=', self.responsible_id.id), + ], order='product_price asc', limit=1) vendor_id = purchase_price.vendor_id.id price = purchase_price.product_price or 0 diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index d62d7b1e..f9cd7f5b 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -48,6 +48,7 @@ class PurchaseOrder(models.Model): note_description = fields.Char(string='Note', help='bisa diisi sebagai informasi indent barang tertentu atau apapun') has_active_invoice = fields.Boolean(string='Has Active Invoice', compute='_compute_has_active_invoice') description = fields.Char(string='Description', help='bisa diisi sebagai informasi indent barang tertentu atau apapun') + purchase_order_lines = fields.One2many('purchase.order.line', 'order_id', string='Indent', auto_join=True) def _compute_has_active_invoice(self): for order in self: diff --git a/indoteknik_custom/models/sale_monitoring.py b/indoteknik_custom/models/sale_monitoring.py index cfbe6d78..107d5296 100755 --- a/indoteknik_custom/models/sale_monitoring.py +++ b/indoteknik_custom/models/sale_monitoring.py @@ -81,12 +81,12 @@ class SaleMonitoring(models.Model): SUM(smd.qty_so_invoiced) AS qty_so_invoiced, sum(smd.qty_reserved) as qty_reserved, CASE - when sum(qty_so_invoiced) = sum(qty_so) then 'Invoiced' when sum(qty_so_delivered) = sum(qty_so) then 'Delivered' when sum(qty_reserved) >= sum(qty_so) then 'Siap kirim' when sum(qty_po) + sum(qty_reserved) - sum(qty_po_received) < sum(qty_so) then 'Belum/Kurang PO' when sum(qty_po_received) = 0 then 'Belum terima' when sum(qty_po_received) < sum(qty_po) then 'Terima sebagian' + when sum(qty_so_invoiced) = sum(qty_so) then 'Invoiced' END AS status, get_po_number(smd.sale_order_id) as po_number FROM sale_monitoring_detail smd diff --git a/indoteknik_custom/models/sale_monitoring_detail.py b/indoteknik_custom/models/sale_monitoring_detail.py index dc4caa14..43b0b063 100755 --- a/indoteknik_custom/models/sale_monitoring_detail.py +++ b/indoteknik_custom/models/sale_monitoring_detail.py @@ -31,12 +31,12 @@ class SaleMonitoringDetail(models.Model): SELECT *, CASE - when qty_so_invoiced = qty_so then 'Invoiced' when qty_so_delivered = qty_so then 'Delivered' when qty_reserved >= qty_so then 'Siap kirim' when qty_po + qty_reserved - qty_po_received < qty_so then 'Belum/Kurang PO' when qty_po_received = 0 then 'Belum terima' when qty_po_received < qty_po then 'Terima sebagian' + when qty_so_invoiced = qty_so then 'Invoiced' END AS status FROM ( diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 9324930e..cc6941a9 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -1,5 +1,6 @@ from odoo import fields, models, api, _ from odoo.exceptions import UserError +from datetime import datetime import logging, random, string, requests, math, json, re _logger = logging.getLogger(__name__) @@ -81,6 +82,16 @@ class SaleOrder(models.Model): email = fields.Char(string='Email') picking_iu_id = fields.Many2one('stock.picking', 'Picking IU') helper_by_id = fields.Many2one('res.users', 'Helper By') + # picking_ids = fields.Many2many('stock.picking', string='Pickings', compute='_get_pickings', readonly=True, copy=False, search="_search_picking_ids") + + # def _get_pickings(self): + # state = ['assigned'] + # for order in self: + # pickings = self.env['stock.picking'].search([ + # ('sale_id.id', '=', order.id), + # ('state', 'in', state) + # ]) + # order.picking_ids = pickings @api.model def action_multi_update_state(self): @@ -193,8 +204,39 @@ class SaleOrder(models.Model): sale.so_status = 'sebagian' else: sale.so_status = 'menunggu' + + for picking in sale.picking_ids: + sum_qty_pick = sum(move_line.product_uom_qty for move_line in picking.move_ids_without_package) + sum_qty_reserved = sum(move_line.product_uom_qty for move_line in picking.move_line_ids_without_package) + if picking.state == 'done': + continue + elif sum_qty_pick == sum_qty_reserved and not picking.date_reserved:# baru ke reserved + current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S') + picking.date_reserved = current_time + elif sum_qty_pick == sum_qty_reserved:# sudah ada data reserved + picking.date_reserved = picking.date_reserved + else: + picking.date_reserved = '' + _logger.info('Calculate SO Status %s' % sale.id) + # def _search_picking_ids(self, operator, value): + # if operator == 'in' and value: + # self.env.cr.execute(""" + # SELECT array_agg(so.sale_id) + # FROM stock_picking so + # WHERE + # so.sale_id is not null and so.id = ANY(%s) + # """, (list(value),)) + # so_ids = self.env.cr.fetchone()[0] or [] + # return [('id', 'in', so_ids)] + # elif operator == '=' and not value: + # order_ids = self._search([ + # ('order_line.invoice_lines.move_id.move_type', 'in', ('out_invoice', 'out_refund')) + # ]) + # return [('id', 'not in', order_ids)] + # return ['&', ('order_line.invoice_lines.move_id.move_type', 'in', ('out_invoice', 'out_refund')), ('order_line.invoice_lines.move_id', operator, value)] + @api.onchange('partner_shipping_id') def onchange_partner_shipping(self): self.real_shipping_id = self.partner_shipping_id diff --git a/indoteknik_custom/models/sale_order_line.py b/indoteknik_custom/models/sale_order_line.py index d0985de5..eda003c7 100644 --- a/indoteknik_custom/models/sale_order_line.py +++ b/indoteknik_custom/models/sale_order_line.py @@ -72,21 +72,37 @@ class SaleOrderLine(models.Model): cost = self.product_id.standard_price self.purchase_price = cost else: + # purchase_price = self.env['purchase.pricelist'].search( + # [('vendor_id', '=', self.vendor_id.id), ('product_id', '=', self.product_id.id)], limit=1) purchase_price = self.env['purchase.pricelist'].search( - [('vendor_id', '=', self.vendor_id.id), ('product_id', '=', self.product_id.id)], limit=1) - self.purchase_price = purchase_price.product_price + [('vendor_id', '=', self.vendor_id.id), ('product_id', '=', self.product_id.id)], + limit=1, order='count_trx_po desc, count_trx_po_vendor desc') + self.purchase_price = self._get_valid_purchase_price(purchase_price) self.purchase_tax_id = 22 + def _get_valid_purchase_price(self, purchase_price): + p_price = 0 + if purchase_price.system_price > 0 and purchase_price.product_price > 0: + if purchase_price.human_last_update > purchase_price.system_last_update: + p_price = purchase_price.product_price + else: + p_price = purchase_price.system_price + elif purchase_price.system_price > 0 and purchase_price.product_price == 0: + p_price = purchase_price.system_price + elif purchase_price.system_price == 0 and purchase_price.product_price > 0: + p_price = purchase_price.product_price + return p_price + @api.onchange('product_id') def product_id_change(self): super(SaleOrderLine, self).product_id_change() for line in self: if line.product_id and line.product_id.type == 'product': purchase_price = self.env['purchase.pricelist'].search( - [('product_id', '=', self.product_id.id)], limit=1, order='product_price ASC') + [('product_id', '=', self.product_id.id)], limit=1, order='count_trx_po desc, count_trx_po_vendor desc') line.vendor_id = purchase_price.vendor_id line.tax_id = line.order_id.sales_tax_id - line.purchase_price = purchase_price.product_price + line.purchase_price = self._get_valid_purchase_price(purchase_price) def compute_delivery_amt_line(self): for line in self: diff --git a/indoteknik_custom/models/solr/product_template.py b/indoteknik_custom/models/solr/product_template.py index 2bbcab9c..648a0625 100644 --- a/indoteknik_custom/models/solr/product_template.py +++ b/indoteknik_custom/models/solr/product_template.py @@ -137,7 +137,7 @@ class ProductTemplate(models.Model): price_tier = price_doc.get(f"{price_tier_key}_f", 0) # When price tier is 0 or variant_price less than price tier then use variant price - if price_tier == 0 or variant_price < price_tier: + if price_tier == 0 or (variant_price < price_tier and variant_price > 0): price_doc[f"{discount_tier_key}_f"] = variant_discount price_doc[f"{price_tier_key}_f"] = variant_price diff --git a/indoteknik_custom/models/solr/x_manufactures.py b/indoteknik_custom/models/solr/x_manufactures.py index 375b7708..98b1d01d 100644 --- a/indoteknik_custom/models/solr/x_manufactures.py +++ b/indoteknik_custom/models/solr/x_manufactures.py @@ -40,7 +40,7 @@ class XManufactures(models.Model): document.update({ 'id': brands.id, 'display_name_s': brands.display_name, - 'name_s': brands.x_name, + 'name_s': brands.x_name.lower(), 'sequence_i': brands.sequence or '', 'negara_asal_s': brands.x_negara_asal or '', 'short_desc_s': brands.x_short_desc or '', diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py index 626e842d..a5e533b1 100644 --- a/indoteknik_custom/models/stock_picking.py +++ b/indoteknik_custom/models/stock_picking.py @@ -1,6 +1,7 @@ from odoo import fields, models, api, _ from odoo.exceptions import AccessError, UserError, ValidationError from odoo.tools.float_utils import float_is_zero +from datetime import datetime from itertools import groupby import pytz, datetime @@ -74,6 +75,7 @@ class StockPicking(models.Model): purchase_representative_id = fields.Many2one('res.users', related='move_lines.purchase_line_id.order_id.user_id', string="Purchase Representative", readonly=True) carrier_id = fields.Many2one('delivery.carrier', string='Shipping Method') shipping_status = fields.Char(string='Shipping Status', compute="_compute_shipping_status") + date_reserved = fields.Datetime(string="Date Reserved", help='Tanggal ter-reserved semua barang nya') def _compute_shipping_status(self): for rec in self: @@ -309,6 +311,10 @@ class StockPicking(models.Model): if product: product.product_tmpl_id._create_solr_queue('_sync_product_stock_to_solr') + if not self.date_reserved: + current_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') + self.date_reserved = current_time + res = super(StockPicking, self).button_validate() self.calculate_line_no() return res diff --git a/indoteknik_custom/models/stock_warehouse_orderpoint.py b/indoteknik_custom/models/stock_warehouse_orderpoint.py new file mode 100644 index 00000000..277c8dc3 --- /dev/null +++ b/indoteknik_custom/models/stock_warehouse_orderpoint.py @@ -0,0 +1,10 @@ +from odoo import fields, models, api, _ + +class StockWarehouseOrderpoint(models.Model): + _inherit = 'stock.warehouse.orderpoint' + + responsible_id = fields.Many2one('res.users', string='Responsible', compute='_compute_responsible') + + def _compute_responsible(self): + for stock in self: + stock.responsible_id = stock.product_id.x_manufacture.user_id diff --git a/indoteknik_custom/models/x_manufactures.py b/indoteknik_custom/models/x_manufactures.py index e48a5367..abedf0cf 100755 --- a/indoteknik_custom/models/x_manufactures.py +++ b/indoteknik_custom/models/x_manufactures.py @@ -47,6 +47,8 @@ class XManufactures(models.Model): parent_id = fields.Many2one('x_manufactures', string='Parent', help='Parent Brand tersebut') category_ids = fields.Many2many('product.public.category', string='Category', help='Brand tsb memiliki Category apa saja') vendor_ids = fields.Many2many('res.partner', string='Vendor', compute='_compute_vendor_ids') + # user_id = fields.Many2one('res.users', string='Responsible', domain="['|'('id', '=', 19), ('id', '=', 6)]", help="Siapa yang bertanggung jawab") + user_id = fields.Many2one('res.users', string='Responsible', help="Siapa yang bertanggung jawab") def _compute_vendor_ids(self): for manufacture in self: diff --git a/indoteknik_custom/views/automatic_purchase.xml b/indoteknik_custom/views/automatic_purchase.xml index 49751f4e..0478304e 100644 --- a/indoteknik_custom/views/automatic_purchase.xml +++ b/indoteknik_custom/views/automatic_purchase.xml @@ -10,6 +10,7 @@ <field name="description"/> <field name="notification" readonly="1"/> <field name="is_po" readonly="1"/> + <field name="responsible_id"/> </tree> </field> </record> @@ -57,6 +58,7 @@ <group> <field name="date_doc"/> <field name="vendor_id"/> + <field name="responsible_id"/> <field name="description"/> <field name="notification" readonly="1"/> </group> diff --git a/indoteknik_custom/views/purchase_order.xml b/indoteknik_custom/views/purchase_order.xml index d564f260..8f7ea6df 100755 --- a/indoteknik_custom/views/purchase_order.xml +++ b/indoteknik_custom/views/purchase_order.xml @@ -79,6 +79,7 @@ <field name="description"/> <field name="total_so_percent_margin"/> <field name="has_active_invoice" invisible="1" /> + <field name="purchase_order_lines"/> </field> <field name="order_line" position="attributes"> @@ -96,6 +97,12 @@ <xpath expr="//form/sheet/notebook/page/field[@name='order_line']/tree/field[@name='product_qty']" position="attributes"> <attribute name="attrs">{'readonly': [], 'required': True}</attribute> </xpath> + + <xpath expr="//form/sheet/notebook/page[@name='purchase_delivery_invoice']" position="before"> + <page string="Indent" name="purchase_order_lines_indent"> + <field name="purchase_order_lines"/> + </page> + </xpath> </field> </record> </data> @@ -165,4 +172,16 @@ <field name="active">True</field> </record> </data> + <data> + <record id="purchase_order_line_indent_tree" model="ir.ui.view"> + <field name="name">purchase.order.line.indent.tree</field> + <field name="model">purchase.order.line</field> + <field name="arch" type="xml"> + <tree editable="top" create="false" delete="false"> + <field name="product_id" readonly="1"/> + <field name="indent"/> + </tree> + </field> + </record> + </data> </odoo>
\ No newline at end of file diff --git a/indoteknik_custom/views/stock_picking.xml b/indoteknik_custom/views/stock_picking.xml index 3702dcf8..b0932d5a 100644 --- a/indoteknik_custom/views/stock_picking.xml +++ b/indoteknik_custom/views/stock_picking.xml @@ -72,6 +72,7 @@ /> </field> <field name="group_id" position="before"> + <field name="date_reserved"/> <field name="is_internal_use" string="Internal Use" type="object" diff --git a/indoteknik_custom/views/stock_warehouse_orderpoint.xml b/indoteknik_custom/views/stock_warehouse_orderpoint.xml new file mode 100644 index 00000000..038b09cc --- /dev/null +++ b/indoteknik_custom/views/stock_warehouse_orderpoint.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<odoo> + <data> + <record id="stock_warehouse_orderpoint_inherit" model="ir.ui.view"> + <field name="name">stock.warehouse.orderpoint.tree</field> + <field name="model">stock.warehouse.orderpoint</field> + <field name="inherit_id" ref="stock.view_warehouse_orderpoint_tree_editable_config"/> + <field name="arch" type="xml"> + <field name="product_uom_name" position="after"> + <field name="responsible_id" optional="hide"/> + </field> + </field> + </record> + </data> +</odoo>
\ No newline at end of file diff --git a/indoteknik_custom/views/x_manufactures.xml b/indoteknik_custom/views/x_manufactures.xml index f68a0e00..d413be12 100755 --- a/indoteknik_custom/views/x_manufactures.xml +++ b/indoteknik_custom/views/x_manufactures.xml @@ -24,6 +24,7 @@ <field name="x_manufacture_service_center"/> <field name="cache_reset_status"/> <field name="parent_id"/> + <field name="user_id" optional="hide"/> </tree> </field> </record> @@ -46,6 +47,7 @@ <field name="cache_reset_status"/> <field name="parent_id"/> <field name="category_ids" widget="many2many_tags"/> + <field name="user_id"/> </group> <group> <field name="x_logo_manufacture" widget="image"/> |
