Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[13.0] [IMP] Purchase: onchange quantity hook #56

Open
wants to merge 2 commits into
base: 13.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion addons/mrp/models/stock_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ def _compute_kit_quantities(self, product_id, kit_qty, kit_bom, filters):
# Then, we collect every relevant moves related to a specific component
# to know how many are considered delivered.
uom_qty_per_kit = bom_line_data['qty'] / bom_line_data['original_qty']
qty_per_kit = bom_line.product_uom_id._compute_quantity(uom_qty_per_kit, bom_line.product_id.uom_id)
qty_per_kit = bom_line.product_uom_id._compute_quantity(uom_qty_per_kit, bom_line.product_id.uom_id, round=False)
if not qty_per_kit:
continue
incoming_moves = bom_line_moves.filtered(filters['incoming_moves'])
Expand Down
6 changes: 5 additions & 1 deletion addons/purchase/models/purchase.py
Original file line number Diff line number Diff line change
Expand Up @@ -699,11 +699,15 @@ def onchange_product_id_warning(self):
return {'warning': warning}
return {}

def _prepare_select_seller_params(self):
self.ensure_one()
return {'order_id': self.order_id}

@api.onchange('product_qty', 'product_uom')
def _onchange_quantity(self):
if not self.product_id:
return
params = {'order_id': self.order_id}
params = self._prepare_select_seller_params()
seller = self.product_id._select_seller(
partner_id=self.partner_id,
quantity=self.product_qty,
Expand Down
46 changes: 46 additions & 0 deletions addons/sale_mrp/tests/test_sale_mrp_kit_bom.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,49 @@ def test_sale_mrp_kit_bom_cogs(self):
cogs_aml = amls.filtered(lambda aml: aml.account_id == self.expense_account)
self.assertAlmostEqual(cogs_aml.debit, 2.53)
self.assertEqual(cogs_aml.credit, 0)

def test_qty_delivered_with_bom(self):
"""Check the quantity delivered, when a bom line has a non integer quantity"""

self.kit = self._create_product('Kit', 'product', 0.00)
self.comp = self._create_product('Component', 'product', 0.00)

# Create BoM for Kit
bom_product_form = Form(self.env['mrp.bom'])
bom_product_form.product_id = self.kit
bom_product_form.product_tmpl_id = self.kit.product_tmpl_id
bom_product_form.product_qty = 1.0
bom_product_form.type = 'phantom'
with bom_product_form.bom_line_ids.new() as bom_line:
bom_line.product_id = self.comp
bom_line.product_qty = 0.08600
self.bom = bom_product_form.save()


self.customer = self.env['res.partner'].create({
'name': 'customer',
})

so = self.env['sale.order'].create({
'partner_id': self.customer.id,
'order_line': [
(0, 0, {
'name': self.kit.name,
'product_id': self.kit.id,
'product_uom_qty': 10.0,
'product_uom': self.kit.uom_id.id,
'price_unit': 1,
'tax_id': False,
})],
})
so.action_confirm()

self.assertTrue(so.picking_ids)
self.assertEqual(so.order_line.qty_delivered, 0)

picking = so.picking_ids
picking.move_lines.quantity_done = 0.86000
picking.button_validate()

# Checks the delivery amount (must be 10).
self.assertEqual(so.order_line.qty_delivered, 10)