Skip to content

Commit

Permalink
Merge PR #353 into 12.0
Browse files Browse the repository at this point in the history
Signed-off-by legalsylvain
  • Loading branch information
github-grap-bot committed Feb 5, 2024
2 parents da60b03 + 4944884 commit 213b841
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
<field name="model">bom.print.purchase.list.wizard</field>
<field name="arch" type="xml">
<form string="Print Purchase list">
<div class="wizard_options">
<div name="wizard_options" class="wizard_options">
<h5>🔧 Choose options</h5><br/>
<label for="option_group_by_product_category"/><field name="option_group_by_product_category" widget="boolean_toggle"/><br/>
<label for="option_display_cost"/><field name="option_display_cost" widget="boolean_toggle"/><br/>
<label for="option_print_bom"/><field name="option_print_bom" widget="boolean_toggle"/><br/>
</div>
<div class="Notes">
<h5>📝 Informations on PDF</h5><br/>
<h5>📝 Informations on PDF</h5>
<group colspan="2">
<group col="4" colspan="2">
<field name="title_for_pdf"/><br/>
Expand Down
1 change: 1 addition & 0 deletions mrp_sale_grouped/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"views/view_sale_order.xml",
"wizard/view_sale_grouped_wizard.xml",
"wizard/x2m_matrix_grouped_sales.xml",
"wizard/view_production_assistant_wizard.xml",
"views/action.xml",
],
"installable": True,
Expand Down
7 changes: 0 additions & 7 deletions mrp_sale_grouped/tests/test_mrp_sale_grouped.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# @author: Quentin DUPONT (quentin.dupont@grap.coop)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo.exceptions import Warning as UserError
from odoo.tests.common import TransactionCase


Expand Down Expand Up @@ -65,9 +64,3 @@ def test_05_check_wizard_production_with_boms(self):
active_ids=[self.mrp_sale_grouped_with_boms.id],
active_model="mrp.sale.grouped",
).create({})

def test_06_check_wizard_production_without_boms(self):
with self.assertRaises(UserError):
self.wizard_purchase_list_obj.with_context(
active_ids=[self.mrp_sale_grouped_1.id], active_model="mrp.sale.grouped"
).create({})
80 changes: 34 additions & 46 deletions mrp_sale_grouped/wizard/bom_print_purchase_list_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,26 @@
# @author: Quentin DUPONT (quentin.dupont@grap.coop)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import _, api, models
from odoo.exceptions import UserError
from odoo import api, fields, models


class BomPrintPurchaseListWizard(models.TransientModel):
_inherit = "bom.print.purchase.list.wizard"

missing_boms_text = fields.Char(
default=lambda s: s._default_missing_boms_text(),
)

def _get_sale_grouped_from_context(self):
return self.env["mrp.sale.grouped"].browse(
self.env.context.get("active_ids", [])
)

@api.model
def _default_no_origin(self):
context = self.env.context
active_model = context.get("active_model")
if active_model == "mrp.sale.grouped":
sale_grouped_active_id = context.get("active_ids", [])
sale_grouped_obj = self.env["mrp.sale.grouped"]
sale_grouped_obj.browse(sale_grouped_active_id)

# Handle production_date
if context.get("active_model") == "mrp.sale.grouped":
no_origin = False
else:
no_origin = True
Expand All @@ -32,13 +35,8 @@ def _default_no_origin(self):
def _default_title_for_pdf(self):
context = self.env.context

active_model = context.get("active_model")
if active_model == "mrp.sale.grouped":
sale_grouped_active_id = context.get("active_ids", [])
sale_grouped_obj = self.env["mrp.sale.grouped"]
sale_grouped = sale_grouped_obj.browse(sale_grouped_active_id)

# Handle production_date
if context.get("active_model") == "mrp.sale.grouped":
sale_grouped = self._get_sale_grouped_from_context()
title_for_pdf = sale_grouped.name
else:
title_for_pdf = False
Expand All @@ -52,13 +50,8 @@ def _default_title_for_pdf(self):
def _default_notes(self):
context = self.env.context

active_model = context.get("active_model")
if active_model == "mrp.sale.grouped":
sale_grouped_active_id = context.get("active_ids", [])
sale_grouped_obj = self.env["mrp.sale.grouped"]
sale_grouped = sale_grouped_obj.browse(sale_grouped_active_id)

# Handle production_date
if context.get("active_model") == "mrp.sale.grouped":
sale_grouped = self._get_sale_grouped_from_context()
notes_for_pdf = sale_grouped.notes
else:
notes_for_pdf = False
Expand All @@ -72,13 +65,8 @@ def _default_notes(self):
def _default_production_date(self):
context = self.env.context

active_model = context.get("active_model")
if active_model == "mrp.sale.grouped":
sale_grouped_active_id = context.get("active_ids", [])
sale_grouped_obj = self.env["mrp.sale.grouped"]
sale_grouped = sale_grouped_obj.browse(sale_grouped_active_id)

# Handle production_date
if context.get("active_model") == "mrp.sale.grouped":
sale_grouped = self._get_sale_grouped_from_context()
production_date = sale_grouped.date
else:
production_date = False
Expand All @@ -88,15 +76,27 @@ def _default_production_date(self):
self.with_context(context, production_date=production_date),
)._default_production_date()

@api.model
def _default_missing_boms_text(self):
context = self.env.context

if context.get("active_model") == "mrp.sale.grouped":
sale_grouped = self._get_sale_grouped_from_context()
# Get name of products without any BoM
missing_boms_text = ", ".join(
sale_grouped.product_wo_bom_ids.mapped("display_name")
)
else:
missing_boms_text = False

return missing_boms_text

@api.model
def _default_line_ids(self):
context = self.env.context
active_model = context.get("active_model")

if active_model == "mrp.sale.grouped":
sale_grouped_active_id = context.get("active_ids", [])
sale_grouped_obj = self.env["mrp.sale.grouped"]
sale_grouped = sale_grouped_obj.browse(sale_grouped_active_id)
if context.get("active_model") == "mrp.sale.grouped":
sale_grouped = self._get_sale_grouped_from_context()
order_ids = sale_grouped.mapped("order_ids")

missing_boms = {}
Expand Down Expand Up @@ -126,18 +126,6 @@ def _default_line_ids(self):
# Change boms_and_quantities for the expected format
boms_and_quantities = list(boms_and_quantities.values())

if missing_boms:
boms_text = ", ".join(missing_boms.values())
message = (
(
_(
"These products don't have any Bill Of Material: %s \
\nCreate them before launching the assistant again."
)
)
% boms_text
)
raise UserError(message)
else:
boms_and_quantities = []

Expand Down
24 changes: 24 additions & 0 deletions mrp_sale_grouped/wizard/view_production_assistant_wizard.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2024 - Today: GRAP (http://www.grap.coop)
@author: Quentin DUPONT (quentin.dupont@grap.coop)
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
-->
<odoo>

<record id="view_production_assistant_wizard" model="ir.ui.view">
<field name="model">bom.print.purchase.list.wizard</field>
<field name="inherit_id" ref="mrp_bom_purchase.view_bom_print_purchase_list_wizard_form" />
<field name="arch" type="xml">
<xpath expr="//div[@name='wizard_options']" position="before">
<div class="other_text alert alert-info col-8" role="status">
These products are sold but don't have any Bill Of Material, so they can't be
in this Production assistant:
<b><field name="missing_boms_text" readonly="1"/></b>
</div>
<br/>
</xpath>
</field>
</record>

</odoo>

0 comments on commit 213b841

Please sign in to comment.