Skip to content

Commit 33090ef

Browse files
rlizanavictoralmau
authored andcommittedAug 11, 2022
[ADD] delivery_price_method
1 parent 8161267 commit 33090ef

10 files changed

+177
-0
lines changed
 

‎delivery_price_method/__init__.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Copyright 2020 Trey, Kilobytes de Soluciones
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
from . import models

‎delivery_price_method/__manifest__.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copyright 2020 Trey, Kilobytes de Soluciones
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
{
4+
'name': 'Delivery Price Method',
5+
'summary': 'Provides fields to be able to contemplate the tracking states'
6+
'and also adds a global fields',
7+
'author': 'Trey (www.trey.es), '
8+
'Odoo Community Association (OCA)',
9+
'website': 'https://github.com/OCA/delivery-carrier',
10+
'license': 'AGPL-3',
11+
'category': 'Delivery',
12+
'version': '12.0.1.0.0',
13+
'depends': [
14+
'delivery',
15+
],
16+
'data': [
17+
'views/delivery_carrier_views.xml',
18+
],
19+
}
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Copyright 2020 Trey, Kilobytes de Soluciones
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
from . import delivery_carrier
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Copyright 2020 Trey, Kilobytes de Soluciones
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
from odoo import fields, models
4+
5+
6+
class DeliveryCarrier(models.Model):
7+
_inherit = 'delivery.carrier'
8+
9+
# You must add next method to your carrier model if want use this price
10+
# method
11+
#
12+
# def [CARRIER]_rate_shipment(self, order):
13+
# return self.price_method_rate_shipment(order)
14+
15+
price_method = fields.Selection(
16+
selection=[
17+
('fixed', 'Fixed price'),
18+
('base_on_rule', 'Based on Rules'),
19+
],
20+
string='Price method',
21+
default='fixed',
22+
)
23+
24+
def price_method_rate_shipment(self, order):
25+
return getattr(self, '%s_rate_shipment' % self.price_method)(order)
26+
27+
def send_shipping(self, pickings):
28+
res = super().send_shipping(pickings)
29+
rates = getattr(self, '%s_send_shipping' % self.price_method)(pickings)
30+
for index, rate in enumerate(rates):
31+
res[index]['exact_price'] = rate['exact_price']
32+
return res
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
* `Trey <https://www.trey.es>`_:
2+
* Roberto Lizana <roberto@trey.es>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Tis module adds additional functions that will be necessary for the operator
2+
developments.
3+
4+
It provides a system to rate the shipping price based on a fixed price or based on rules.
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Only available in carriers that have been developed using this module, please consult yours carriers addons.
2+
3+
The carrier form will have a new field * Price method * to use fixed or rule based method.
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Copyright 2020 Trey, Kilobytes de Soluciones
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
from . import test_delivery_price_method
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
Copyright 2020 Trey, Kilobytes de Soluciones
4+
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
5+
-->
6+
<odoo>
7+
<record id="view_delivery_carrier_form" model="ir.ui.view">
8+
<field name="model">delivery.carrier</field>
9+
<field name="inherit_id" ref="delivery.view_delivery_carrier_form"/>
10+
<field name="arch" type="xml">
11+
<xpath expr="//field[@name='integration_level']" position="after">
12+
<field name="price_method" attrs="{'invisible': [('delivery_type', 'in', ['fixed', 'base_on_rule'])]}"/>
13+
</xpath>
14+
<xpath expr="(//page)[1]" position="before">
15+
<page string="Pricing" attrs="{'invisible': [('delivery_type', 'in', ['fixed', 'base_on_rule'])]}">
16+
<group attrs="{'invisible':[('price_method', '!=', 'fixed')]}">
17+
<group>
18+
<field name="fixed_price"/>
19+
</group>
20+
</group>
21+
<group name="general" attrs="{'invisible':[('price_method', '!=', 'base_on_rule')]}">
22+
<field name="price_rule_ids" nolabel="1"/>
23+
</group>
24+
</page>
25+
</xpath>
26+
</field>
27+
</record>
28+
</odoo>

0 commit comments

Comments
 (0)
Please sign in to comment.