diff options
| author | trisusilo48 <tri.susilo@altama.co.id> | 2024-12-05 14:47:42 +0700 |
|---|---|---|
| committer | trisusilo48 <tri.susilo@altama.co.id> | 2024-12-05 14:47:42 +0700 |
| commit | 1e9e0c28ee4dc63f1465affac6d98ae213d9f283 (patch) | |
| tree | e48922d3885f3c1870f24cfad2c708389468d722 /indoteknik_custom/models/product_template.py | |
| parent | 4d5a0a6e2d997e323f8670172226f613b7673d62 (diff) | |
| parent | 4eac4d0709ec5d9e03b517a39cb67acbc35e2932 (diff) | |
Merge branch 'production' of https://bitbucket.org/altafixco/indoteknik-addons into production
Diffstat (limited to 'indoteknik_custom/models/product_template.py')
| -rwxr-xr-x | indoteknik_custom/models/product_template.py | 82 |
1 files changed, 60 insertions, 22 deletions
diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py index 25473ab8..6fb8c7a0 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -1,4 +1,4 @@ -from odoo import fields, models, api +from odoo import fields, models, api, tools, _ from datetime import datetime, timedelta, date from odoo.exceptions import UserError import logging @@ -61,11 +61,12 @@ class ProductTemplate(models.Model): sni = fields.Boolean(string='SNI') tkdn = fields.Boolean(string='TKDN') short_spesification = fields.Char(string='Short Spesification') + merchandise_ok = fields.Boolean(string='Product Promotion') @api.constrains('name', 'internal_reference', 'x_manufacture') def required_public_categ_ids(self): for rec in self: - if not rec.public_categ_ids: + if not rec.public_categ_ids and rec.type == 'product': raise UserError('Field Categories harus diisi') def _get_qty_sold(self): @@ -377,6 +378,7 @@ class ProductProduct(models.Model): max_qty_reorder = fields.Float(string='Max Qty Reorder', compute='_get_max_qty_reordering_rule') qty_rpo = fields.Float(string='Qty RPO', compute='_get_qty_rpo') plafon_qty = fields.Float(string='Max Plafon', compute='_get_plafon_qty_product') + merchandise_ok = fields.Boolean(string='Product Promotion') def _get_clean_website_description(self): for rec in self: @@ -386,7 +388,7 @@ class ProductProduct(models.Model): @api.constrains('name', 'internal_reference', 'x_manufacture') def required_public_categ_ids(self): for rec in self: - if not rec.public_categ_ids: + if not rec.public_categ_ids and rec.type == 'product': raise UserError('Field Categories harus diisi') @api.constrains('active') @@ -482,33 +484,38 @@ class ProductProduct(models.Model): def _get_qty_incoming_bandengan(self): for product in self: - qty_incoming = self.env['stock.move'].search([ - ('product_id', '=', product.id), - ('location_dest_id', 'in', [57, 83]), - ('state', 'not in', ['done', 'cancel']) - ]) - qty = sum(qty_incoming.mapped('product_uom_qty')) + qty = self.env['v.move.outstanding'].read_group( + domain=[ + ('product_id', '=', product.id), + ('location_dest_id', 'in', [57, 83]), + ], + fields=['qty_need'], + groupby=[] + )[0].get('qty_need', 0.0) product.qty_incoming_bandengan = qty def _get_qty_incoming_bandengan_with_exclude(self): for product in self: - qty_incoming = self.env['stock.move'].search([ - ('product_id', '=', product.id), - ('location_dest_id', 'in', [57, 83]), - ('state', 'not in', ['done', 'cancel']) - ]) - qty = sum(qty_incoming.mapped('product_uom_qty')) + qty = self.env['v.move.outstanding'].read_group( + domain=[ + ('product_id', '=', product.id), + ('location_dest_id', 'in', [57, 83]), + ], + fields=['qty_need'], + groupby=[] + )[0].get('qty_need', 0.0) product.qty_incoming_bandengan = qty def _get_qty_outgoing_bandengan(self): for product in self: - qty_incoming = self.env['stock.move'].search([ - ('product_id', '=', product.id), - ('location_dest_id', '=', 5), - ('location_id', 'in', [57, 83]), - ('state', 'not in', ['done', 'cancel']) - ]) - qty = sum(qty_incoming.mapped('product_uom_qty')) + qty = self.env['v.move.outstanding'].read_group( + domain=[ + ('product_id', '=', product.id), + ('location_id', 'in', [57, 83]), + ], + fields=['qty_need'], + groupby=[] + )[0].get('qty_need', 0.0) product.qty_outgoing_bandengan = qty def _get_qty_onhand_bandengan(self): @@ -598,3 +605,34 @@ class ProductProduct(models.Model): ('end_date', '>=', current_time) ], limit=1) return pricelist + + +class OutstandingMove(models.Model): + _name = 'v.move.outstanding' + _auto = False + _rec_name = 'id' + + id = fields.Integer(string='ID') + product_id = fields.Many2one('product.product', string='Product') + reference = fields.Char(string='Reference', help='Nomor Dokumen terkait') + qty_need = fields.Float(string='Qty Need', help='Qty yang akan outgoing / incoming') + location_id = fields.Many2one('stock.location', string='Location', help='Lokasi asal') + location_dest_id = fields.Many2one('stock.location', string='Location To', help='Lokasi tujuan') + + def init(self): + # where clause 'state in' follow the origin of outgoing and incoming odoo + tools.drop_view_if_exists(self.env.cr, self._table) + self.env.cr.execute(""" + CREATE OR REPLACE VIEW %s AS + select sm.id, sm.reference, sm.product_id, + sm.product_uom_qty as qty_need, + sm.location_id, sm.location_dest_id + from stock_move sm + where 1=1 + and sm.state in( + 'waiting', + 'confirmed', + 'assigned', + 'partially_available' + ) + """ % self._table) |
