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

[14.0][IMP] custom_mrp_line_cost: Add default function to container. #509

Merged
merged 1 commit into from
Feb 24, 2025
Merged
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
31 changes: 16 additions & 15 deletions custom_mrp_line_cost/models/mrp_production.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,21 +258,22 @@ def button_calculate_costs(self):
).mapped("qty_done")
)
)
i = qty.index(max(qty))
max_lot = lots[i]
max_qty = qty[i]
if max_lot and max_qty:
lot_lines = production.move_line_ids.filtered(
lambda c: c.lot_id == max_lot
)
amount = (production.cost - production.entry_total_amount) + sum(
lot_lines.mapped("amount")
)
price = amount / max_qty
for max_line in lot_lines:
max_line.applied_price = price
max_line.onchange_applied_price()
production._compute_entry_total_amount()
if qty:
i = qty.index(max(qty))
max_lot = lots[i]
max_qty = qty[i]
if max_lot and max_qty:
lot_lines = production.move_line_ids.filtered(
lambda c: c.lot_id == max_lot
)
amount = (
production.cost - production.entry_total_amount
) + sum(lot_lines.mapped("amount"))
price = amount / max_qty
for max_line in lot_lines:
max_line.applied_price = price
max_line.onchange_applied_price()
production._compute_entry_total_amount()
elif (
not production.is_deconstruction
and (production.average_cost)
Expand Down
8 changes: 7 additions & 1 deletion custom_mrp_line_cost/models/stock_move_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ def _default_pallet_id(self):
result = False
return result

container = fields.Integer(string="Containers")
def _default_container(self):
result = 0
if "default_production_id" in self.env.context:
result = 1
return result

container = fields.Integer(string="Containers", default=_default_container)
unit = fields.Integer(string="Unit")
product_unit_container = fields.Integer(
string="Product Unit/Container", related="product_id.unit_container", store=True
Expand Down
4 changes: 2 additions & 2 deletions custom_mrp_line_cost/views/stock_move_line_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<field name="name">stock.move.line.tree.view</field>
<field name="model">stock.move.line</field>
<field name="arch" type="xml">
<tree editable="top">
<tree editable="bottom">
<field
name="production_id"
force_save="1"
Expand Down Expand Up @@ -99,7 +99,7 @@
<field name="name">stock.move.line.tree.view</field>
<field name="model">stock.move.line</field>
<field name="arch" type="xml">
<tree editable="top" limit="300">
<tree editable="bottom" limit="300">
<field name="state" invisible="1" />
<field name="production_id" optional="hide" />
<field name="move_id" invisible="1" />
Expand Down
Loading