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

[16.0][IMP] sale_order_import: Add confirm_order flag to wizard #839

Merged
merged 1 commit into from
Oct 25, 2023
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
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
Loading