Skip to content

Commit

Permalink
[IMP] sale_order_import: add confirm_order flag to wizard
Browse files Browse the repository at this point in the history
When the flag is enabled, the order will be automatically confirmed.
Mostly used when the wizard is used as a tool to import orders.
  • Loading branch information
duongtq committed Oct 25, 2023
1 parent 1e38cbe commit 686723f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
27 changes: 27 additions & 0 deletions sale_order_import/tests/test_order_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,30 @@ def test_with_order_buttons(self):

self.assertEqual(len(so.order_line), 2)
self.assertEqual(so.order_line[0].product_uom_qty, 3)

def test_confirm_order(self):
# Prepare test data
order_file_data = base64.b64encode(
b"<?xml version='1.0' encoding='utf-8'?><root><foo>baz</foo></root>"
)
order_filename = "test_order.xml"
mock_parse_order = mock.patch.object(type(self.wiz_model), "parse_xml_order")
# Create a new form
with Form(
self.wiz_model.with_context(
default_order_filename=order_filename,
default_confirm_order=True,
)
) as form:
with mock_parse_order as mocked:
# Return 'rfq' for doc_type
mocked.return_value = "rfq"
# Set values for the required fields
form.import_type = "xml"
form.order_file = order_file_data
# Test the button with the simulated values
mocked.return_value = self.parsed_order
action = form.save().import_order_button()
so = self.env["sale.order"].browse(action["res_id"])
# Check the state of the order
self.assertEqual(so.state, "sale")
5 changes: 5 additions & 0 deletions sale_order_import/wizard/sale_order_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ class SaleOrderImport(models.TransientModel):
"res.partner", string="Shipping Address", readonly=True
)
sale_id = fields.Many2one("sale.order", string="Quotation to Update")
# Confirm order after creating Sale Order
confirm_order = fields.Boolean(default=False)

@api.onchange("order_file")
def order_file_change(self):
Expand Down Expand Up @@ -320,6 +322,9 @@ def create_order(self, parsed_order, price_source, order_filename=None):
order = soo.create(so_vals)
bdio.post_create_or_update(parsed_order, order, doc_filename=order_filename)
logger.info("Sale Order ID %d created", order.id)
if self.confirm_order:
order.action_confirm()
logger.info("Sale Order ID %d confirmed", order.id)
return order

@api.model
Expand Down

0 comments on commit 686723f

Please sign in to comment.