|
5 | 5 | # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
6 | 6 |
|
7 | 7 |
|
| 8 | +from odoo import Command |
| 9 | +from odoo.tests.common import Form |
| 10 | + |
8 | 11 | from odoo.addons.purchase_sale_inter_company.tests.test_inter_company_purchase_sale import (
|
9 | 12 | TestPurchaseSaleInterCompany,
|
10 | 13 | )
|
@@ -66,3 +69,80 @@ def test_purchase_sale_stock_inter_company(self):
|
66 | 69 | self.purchase_company_a.picking_type_id.warehouse_id.partner_id,
|
67 | 70 | )
|
68 | 71 | self.assertEqual(sale.warehouse_id, self.warehouse_c)
|
| 72 | + |
| 73 | + def test_purchase_sale_stock_dropshipping_inter_company(self): |
| 74 | + self.external_supplier = self.env["res.partner"].create({"name": "Supplier"}) |
| 75 | + self.external_customer = self.env["res.partner"].create({"name": "Customer"}) |
| 76 | + self.dropship_route = self.env.ref("stock_dropshipping.route_drop_shipping") |
| 77 | + self.dropship_product = self.env["product.product"].create( |
| 78 | + [ |
| 79 | + { |
| 80 | + "name": "Dropship product", |
| 81 | + "type": "product", |
| 82 | + "route_ids": [Command.link(self.dropship_route.id)], |
| 83 | + "seller_ids": [ |
| 84 | + Command.create( |
| 85 | + { |
| 86 | + "partner_id": self.partner_company_b.id, |
| 87 | + "min_qty": 0, |
| 88 | + "delay": 5, |
| 89 | + "company_id": self.company_a.id, |
| 90 | + } |
| 91 | + ), |
| 92 | + Command.create( |
| 93 | + { |
| 94 | + "partner_id": self.external_supplier.id, |
| 95 | + "min_qty": 5, |
| 96 | + "delay": 1, |
| 97 | + "company_id": self.company_b.id, |
| 98 | + } |
| 99 | + ), |
| 100 | + ], |
| 101 | + } |
| 102 | + ] |
| 103 | + ) |
| 104 | + |
| 105 | + original_sale_form = Form( |
| 106 | + self.env["sale.order"] |
| 107 | + .with_company(self.company_a) |
| 108 | + .with_user(self.user_company_a) |
| 109 | + ) |
| 110 | + original_sale_form.partner_id = self.external_customer |
| 111 | + |
| 112 | + with original_sale_form.order_line.new() as line_form: |
| 113 | + line_form.product_id = self.dropship_product |
| 114 | + line_form.product_uom_qty = 5.0 |
| 115 | + line_form.price_unit = 100.0 |
| 116 | + original_sale = original_sale_form.save() |
| 117 | + |
| 118 | + original_sale.action_confirm() |
| 119 | + inter_company_po = original_sale._get_purchase_orders() |
| 120 | + inter_company_po.button_confirm() |
| 121 | + inter_company_so = ( |
| 122 | + self.env["sale.order"] |
| 123 | + .with_user(self.user_company_b) |
| 124 | + .search([("auto_purchase_order_id", "=", inter_company_po.id)]) |
| 125 | + ) |
| 126 | + external_po = inter_company_so._get_purchase_orders() |
| 127 | + external_po.button_confirm() |
| 128 | + external_po.picking_ids.move_ids.quantity_done = 3.0 |
| 129 | + backorder_wizard_dict = external_po.picking_ids.button_validate() |
| 130 | + backorder_wizard = Form( |
| 131 | + self.env[backorder_wizard_dict["res_model"]].with_context( |
| 132 | + **backorder_wizard_dict["context"] |
| 133 | + ) |
| 134 | + ).save() |
| 135 | + backorder_wizard.process() |
| 136 | + self.assertEqual(inter_company_so.order_line.qty_delivered, 3.0) |
| 137 | + self.assertEqual(original_sale.order_line.qty_delivered, 3.0) |
| 138 | + backorder = external_po.picking_ids.backorder_ids |
| 139 | + backorder.move_ids.quantity_done = backorder.move_ids.product_qty |
| 140 | + backorder.button_validate() |
| 141 | + self.assertEqual( |
| 142 | + inter_company_so.order_line.qty_delivered, |
| 143 | + inter_company_so.order_line.product_uom_qty, |
| 144 | + ) |
| 145 | + self.assertEqual( |
| 146 | + original_sale.order_line.qty_delivered, |
| 147 | + original_sale.order_line.product_uom_qty, |
| 148 | + ) |
0 commit comments