|
| 1 | +# Copyright 2020 Trey, Kilobytes de Soluciones |
| 2 | +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). |
| 3 | +from odoo.tests.common import TransactionCase |
| 4 | + |
| 5 | + |
| 6 | +class TestDeliveryPriceMethod(TransactionCase): |
| 7 | + |
| 8 | + def setUp(self): |
| 9 | + super().setUp() |
| 10 | + product_shipping_cost = self.env['product.product'].create({ |
| 11 | + 'type': 'service', |
| 12 | + 'name': 'Shipping costs', |
| 13 | + 'standard_price': 10, |
| 14 | + 'list_price': 100, |
| 15 | + }) |
| 16 | + self.carrier = self.env['delivery.carrier'].create({ |
| 17 | + 'name': 'Test carrier', |
| 18 | + 'delivery_type': 'fixed', |
| 19 | + 'product_id': product_shipping_cost.id, |
| 20 | + 'fixed_price': 99.99, |
| 21 | + }) |
| 22 | + |
| 23 | + def test_delivery_price_fixed(self): |
| 24 | + product = self.env.ref('product.product_delivery_01') |
| 25 | + partner = self.env.ref('base.res_partner_12') |
| 26 | + sale = self.env['sale.order'].create({ |
| 27 | + 'partner_id': partner.id, |
| 28 | + 'carrier_id': self.carrier.id, |
| 29 | + 'order_line': [(0, 0, { |
| 30 | + 'product_id': product.id, |
| 31 | + 'product_uom_qty': 1})] |
| 32 | + }) |
| 33 | + sale.get_delivery_price() |
| 34 | + self.assertEquals(sale.delivery_price, 99.99) |
| 35 | + sale.set_delivery_line() |
| 36 | + self.assertEquals(len(sale.order_line), 2) |
| 37 | + sale.action_confirm() |
| 38 | + picking = sale.picking_ids[0] |
| 39 | + self.assertEquals(len(picking.move_lines), 1) |
| 40 | + self.assertEquals(picking.carrier_id, self.carrier) |
| 41 | + picking.action_confirm() |
| 42 | + picking.action_assign() |
| 43 | + self.assertFalse(picking.carrier_price) |
| 44 | + picking.send_to_shipper() |
| 45 | + self.assertEquals(picking.carrier_price, 99.99) |
| 46 | + |
| 47 | + def test_delivery_price_method(self): |
| 48 | + product = self.env.ref('product.product_delivery_01') |
| 49 | + partner = self.env.ref('base.res_partner_12') |
| 50 | + sale = self.env['sale.order'].create({ |
| 51 | + 'partner_id': partner.id, |
| 52 | + 'carrier_id': self.carrier.id, |
| 53 | + 'order_line': [(0, 0, { |
| 54 | + 'product_id': product.id, |
| 55 | + 'product_uom_qty': 1})] |
| 56 | + }) |
| 57 | + self.carrier.write({ |
| 58 | + 'price_method': 'fixed', |
| 59 | + 'fixed_price': 99.99, |
| 60 | + }) |
| 61 | + sale.get_delivery_price() |
| 62 | + self.assertEquals(sale.delivery_price, 99.99) |
| 63 | + self.carrier.write({ |
| 64 | + 'price_method': 'fixed', |
| 65 | + 'fixed_price': 5, |
| 66 | + }) |
| 67 | + sale.get_delivery_price() |
| 68 | + self.assertEquals(sale.delivery_price, 5) |
| 69 | + self.carrier.write({ |
| 70 | + 'delivery_type': 'base_on_rule', |
| 71 | + 'price_method': 'base_on_rule', |
| 72 | + 'fixed_price': 99.99, |
| 73 | + 'price_rule_ids': [(0, 0, { |
| 74 | + 'variable': 'quantity', |
| 75 | + 'operator': '==', |
| 76 | + 'max_value': 1, |
| 77 | + 'list_base_price': 11.11})] |
| 78 | + }) |
| 79 | + sale.get_delivery_price() |
| 80 | + self.assertEquals(sale.delivery_price, 11.11) |
0 commit comments