Skip to content

Commit

Permalink
[MIG] sale_order_import: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
antonioburic committed Jul 8, 2024
1 parent 464e5ff commit 319a88e
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 38 deletions.
2 changes: 1 addition & 1 deletion sale_order_import/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

{
"name": "Sale Order Import",
"version": "16.0.1.2.0",
"version": "17.0.1.0.0",
"category": "Sales Management",
"license": "AGPL-3",
"summary": "Import RFQ or sale orders from files",
Expand Down
20 changes: 8 additions & 12 deletions sale_order_import/models/sale.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,17 @@
class SaleOrder(models.Model):
_inherit = "sale.order"

def name_get(self):
def _compute_display_name(self):
"""Add amount_untaxed in name_get of sale orders"""
res = super().name_get()
res = super()._compute_display_name()
if self._context.get("sale_order_show_amount"):
new_res = []
for sale_id, name in res:
sale = self.browse(sale_id)
for order in self:
# TODO: find a python method to easily display a float + currency
# symbol (before or after) depending on lang of context and currency
name += _(
name = _(
" Amount w/o tax: %(amount)s %(currency)s",
amount=sale.amount_untaxed,
currency=sale.currency_id.name,
amount=order.amount_untaxed,
currency=order.currency_id.name,
)
new_res.append((sale_id, name))
return new_res
else:
return res
order.display_name = name
return res
12 changes: 8 additions & 4 deletions sale_order_import/tests/test_sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@ def setUpClass(cls):
super().setUpClass()
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))

def test_name_get(self):
def test_display_name(self):
sale_order = self.env.ref("sale.sale_order_1")
name = sale_order.name + _(
" Amount w/o tax: %(amount)s %(currency)s",
amount=sale_order.amount_untaxed,
currency=sale_order.currency_id.name,
)
so = self.env["sale.order"].with_context(sale_order_show_amount=True)
name_get_res = so.search([("id", "=", sale_order.id)]).name_get()
self.assertEqual(name, name_get_res[0][1])
so = (
self.env["sale.order"]
.with_context(sale_order_show_amount=True)
.browse(sale_order.id)
)
so._compute_display_name()
self.assertEqual(name, so.display_name)
19 changes: 7 additions & 12 deletions sale_order_import/wizard/sale_order_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ def _parse_file(self, filename, filecontent, detect_doc_type=False):
type=self.import_type.upper(),
)
)
if hasattr(self, "parse_%s_order" % self.import_type):
return getattr(self, "parse_%s_order" % self.import_type)(
if hasattr(self, f"parse_{self.import_type}_order"):
return getattr(self, f"parse_{self.import_type}_order")(
filecontent, detect_doc_type=detect_doc_type
)
else:
Expand Down Expand Up @@ -486,8 +486,9 @@ def _prepare_create_order_line(
vals.pop("order_id")

# Handle additional fields dynamically if available.
# This way, if you add a field to a record and it's value is injected by a parser
# you won't have to override `_prepare_create_order_line` to let it propagate.
# This way, if you add a field to a record
# and it's value is injected by a parser, you won't have to
# override `_prepare_create_order_line` to let it propagate.
for k, v in import_line.items():
if k not in vals and k in solo._fields:
vals[k] = v
Expand Down Expand Up @@ -582,8 +583,7 @@ def update_order_lines(self, parsed_order, order, price_source):
oline.write(write_vals)
if compare_res["to_remove"]:
to_remove_label = [
"%s %s x %s"
% (line.product_uom_qty, line.product_uom.name, line.product_id.name)
f"{line.product_uom_qty} {line.product_uom.name} x {line.product_id.name}" # noqa
for line in compare_res["to_remove"]
]
chatter.append(
Expand All @@ -603,12 +603,7 @@ def update_order_lines(self, parsed_order, order, price_source):
line_vals["order_id"] = order.id
new_line = solo.create(line_vals)
to_create_label.append(
"%s %s x %s"
% (
new_line.product_uom_qty,
new_line.product_uom.name,
new_line.name,
)
f"{new_line.product_uom_qty} {new_line.product_uom.name} x {new_line.name}" # noqa
)
chatter.append(
_(
Expand Down
19 changes: 10 additions & 9 deletions sale_order_import/wizard/sale_order_import_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<group name="technical" invisible="1">
<field name="state" />
</group>
<group colspan="4" name="help-import" states="import">
<group colspan="4" name="help-import" invisible="state != 'import'">
<div colspan="2">
<p
>Upload below the customer order or request for quotation as XML or PDF file. When you click on the Import button:</p>
Expand All @@ -28,22 +28,22 @@
</ol>
</div>
</group>
<group colspan="4" name="help-update" states="update">
<group colspan="4" name="help-update" invisible="state != 'update'">
<div colspan="2">
<p
>Some quotations have been found for this customer ; one of them may correspond to the order or RFQ that you are importing. You can either select an existing quotation to update or create a new one.</p>
</div>
</group>
<group name="import" states="import">
<group name="import" invisible="state != 'import'">
<field name="import_type" />
<field
name="order_file"
filename="order_filename"
attrs="{'readonly': [('import_type', '=', False)]}"
readonly="not import_type"
/>
<field name="order_filename" invisible="1" />
</group>
<group name="update" states="update">
<group name="update" invisible="state != 'update'">
<field name="commercial_partner_id" />
<field
name="partner_shipping_id"
Expand All @@ -59,28 +59,29 @@
<field name="doc_type" />
<field
name="price_source"
attrs="{'invisible': [('doc_type', '!=', 'order')], 'required': [('doc_type', '=', 'order')]}"
invisible="doc_type != 'order'"
required="doc_type == 'order'"
/>
</group>
<footer>
<button
name="import_order_button"
type="object"
states="import"
invisible="state != 'import'"
class="oe_highlight"
string="Import"
/>
<button
name="update_order_button"
type="object"
states="update"
invisible="state != 'update'"
class="oe_highlight"
string="Update Existing"
/>
<button
name="create_order_button"
type="object"
states="update"
invisible="state != 'update'"
class="oe_highlight"
string="Create New"
/>
Expand Down

0 comments on commit 319a88e

Please sign in to comment.