Skip to content

Commit

Permalink
[IMP] Add UoM functionality, simplify some code
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinkhao committed Jun 1, 2021
1 parent 3092709 commit 51959dc
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
44 changes: 39 additions & 5 deletions base_product_mass_addition/models/product_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,59 @@ class ProductProduct(models.Model):

qty_to_process = fields.Float(
compute="_compute_process_qty",
inverse="_inverse_set_process_qty",
inverse="_inverse_quick_vals",
help="Set this quantity to create a new line "
"for this product or update the existing one.",
)
quick_uom_category_id = fields.Many2one(
"uom.category", compute="_compute_quick_uom_category_id"
)
quick_uom_id = fields.Many2one(
"uom.uom",
domain="[('category_id', '=', quick_uom_category_id)]",
compute="_compute_purchase_quick_uom_id",
inverse="_inverse_quick_vals",
)

def _inverse_quick_vals(self):
self._sync_quick_lines()

def _inverse_set_process_qty(self):
@property
def pma_parent(self):
# shorthand for product_mass_addition parent
parent_model = self.env.context.get("parent_model")
parent_id = self.env.context.get("parent_id")
if parent_model:
parent = self.env[parent_model].browse(parent_id)
if parent_model and parent_id:
return self.env[parent_model].browse(parent_id)

def _compute_quick_uom_category_id(self):
raise NotImplementedError

def _sync_quick_lines(self):
parent = self.pma_parent
if parent:
for product in self:
quick_line = parent._get_quick_line(product)
if quick_line:
parent._update_quick_line(product, quick_line)
else:
parent._add_quick_line(product, quick_line._name)

def _default_quick_uom_id(self):
raise NotImplementedError

def _compute_purchase_quick_uom_id(self):
parent = self.pma_parent
if parent:
for rec in self:
quick_line = parent._get_quick_line(rec)
if quick_line:
rec.quick_uom_id = quick_line.product_uom
else:
rec.quick_uom_id = rec._default_quick_uom_id()

def _compute_process_qty(self):
if not self.env.context.get("parent_id"):
if not self.pma_parent:
return

def button_quick_open_product(self):
Expand Down
1 change: 1 addition & 0 deletions base_product_mass_addition/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ Akretion
* Mourad EL HADJ MIMOUNE <[email protected]>
* Pierrick Brun <[email protected]>
* David Béal <[email protected]>
* Kevin Khao <[email protected]>

0 comments on commit 51959dc

Please sign in to comment.