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

[14.0][MIG] delivery_price_method: Migration to 14.0 #518

Merged
merged 15 commits into from
Aug 11, 2022
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
[IMP] delivery_price_method: black, isort, prettier
misern2 authored and victoralmau committed Aug 11, 2022
commit 53a0107381cbf54cf19506fe2a2740d618967088
25 changes: 10 additions & 15 deletions delivery_price_method/__manifest__.py
Original file line number Diff line number Diff line change
@@ -2,19 +2,14 @@
# Copyright 2020 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
'name': 'Delivery Price Method',
'summary': 'Provides fields to be able to contemplate the tracking states'
'and also adds a global fields',
'author': 'Trey (www.trey.es), '
'Odoo Community Association (OCA)',
'website': 'https://github.com/OCA/delivery-carrier',
'license': 'AGPL-3',
'category': 'Delivery',
'version': '12.0.1.0.0',
'depends': [
'delivery',
],
'data': [
'views/delivery_carrier_views.xml',
],
"name": "Delivery Price Method",
"summary": "Provides fields to be able to contemplate the tracking states"
"and also adds a global fields",
"author": "Trey (www.trey.es), " "Odoo Community Association (OCA)",
"website": "https://github.com/OCA/delivery-carrier",
"license": "AGPL-3",
"category": "Delivery",
"version": "12.0.1.0.0",
"depends": ["delivery"],
"data": ["views/delivery_carrier_views.xml"],
}
15 changes: 7 additions & 8 deletions delivery_price_method/models/delivery_carrier.py
Original file line number Diff line number Diff line change
@@ -5,16 +5,16 @@


class DeliveryCarrier(models.Model):
_inherit = 'delivery.carrier'
_inherit = "delivery.carrier"

price_method = fields.Selection(
selection=[
('carrier', 'Carrier obtained price'),
('fixed', 'Fixed price'),
('base_on_rule', 'Based on Rules'),
("carrier", "Carrier obtained price"),
("fixed", "Fixed price"),
("base_on_rule", "Based on Rules"),
],
string='Price method',
default='carrier',
string="Price method",
default="carrier",
)

def rate_shipment(self, order):
@@ -33,8 +33,7 @@ def rate_shipment(self, order):
def send_shipping(self, pickings):
res = super().send_shipping(pickings)
if self.price_method in ("fixed", "base_on_rule"):
rates = getattr(
self, '%s_send_shipping' % self.price_method)(pickings)
rates = getattr(self, "%s_send_shipping" % self.price_method)(pickings)
for index, rate in enumerate(rates):
del rate["tracking_number"] # remove offending key
res[index].update(rate)
98 changes: 53 additions & 45 deletions delivery_price_method/tests/test_delivery_price_method.py
Original file line number Diff line number Diff line change
@@ -9,35 +9,40 @@ class TestDeliveryPriceMethod(SavepointCase):
def setUpClass(cls):
super().setUpClass()
self = cls
product_shipping_cost = self.env['product.product'].create({
'type': 'service',
'name': 'Shipping costs',
'standard_price': 10,
'list_price': 100,
})
self.carrier = self.env['delivery.carrier'].create({
'name': 'Test carrier',
'delivery_type': 'fixed',
'product_id': product_shipping_cost.id,
'fixed_price': 99.99,
})
self.pricelist = self.env["product.pricelist"].create({
"name": "Test pricelist",
"item_ids": [(0, 0, {
"applied_on": "3_global",
"base": "list_price",
})],
})
self.product = self.env.ref('product.product_delivery_01')
self.partner = self.env.ref('base.res_partner_12')
self.sale = self.env['sale.order'].create({
'partner_id': self.partner.id,
'pricelist_id': self.pricelist.id,
'carrier_id': self.carrier.id,
'order_line': [(0, 0, {
'product_id': self.product.id,
'product_uom_qty': 1})]
})
product_shipping_cost = self.env["product.product"].create(
{
"type": "service",
"name": "Shipping costs",
"standard_price": 10,
"list_price": 100,
}
)
self.carrier = self.env["delivery.carrier"].create(
{
"name": "Test carrier",
"delivery_type": "fixed",
"product_id": product_shipping_cost.id,
"fixed_price": 99.99,
}
)
self.pricelist = self.env["product.pricelist"].create(
{
"name": "Test pricelist",
"item_ids": [(0, 0, {"applied_on": "3_global", "base": "list_price"})],
}
)
self.product = self.env.ref("product.product_delivery_01")
self.partner = self.env.ref("base.res_partner_12")
self.sale = self.env["sale.order"].create(
{
"partner_id": self.partner.id,
"pricelist_id": self.pricelist.id,
"carrier_id": self.carrier.id,
"order_line": [
(0, 0, {"product_id": self.product.id, "product_uom_qty": 1})
],
}
)

def test_delivery_price_fixed(self):
sale = self.sale
@@ -56,26 +61,29 @@ def test_delivery_price_fixed(self):
self.assertEquals(picking.carrier_price, 99.99)

def test_delivery_price_method(self):
self.carrier.write({
'price_method': 'fixed',
'fixed_price': 99.99,
})
self.carrier.write({"price_method": "fixed", "fixed_price": 99.99})
sale = self.sale
sale.get_delivery_price()
self.assertEquals(sale.delivery_price, 99.99)
self.carrier.write({
'price_method': 'fixed',
'fixed_price': 5,
})
self.carrier.write({"price_method": "fixed", "fixed_price": 5})
sale.get_delivery_price()
self.assertEquals(sale.delivery_price, 5)
self.carrier.write({
'price_method': 'base_on_rule',
'price_rule_ids': [(0, 0, {
'variable': 'quantity',
'operator': '==',
'max_value': 1,
'list_base_price': 11.11})]
})
self.carrier.write(
{
"price_method": "base_on_rule",
"price_rule_ids": [
(
0,
0,
{
"variable": "quantity",
"operator": "==",
"max_value": 1,
"list_base_price": 11.11,
},
)
],
}
)
sale.get_delivery_price()
self.assertEquals(sale.delivery_price, 11.11)
23 changes: 16 additions & 7 deletions delivery_price_method/views/delivery_carrier_views.xml
Original file line number Diff line number Diff line change
@@ -1,25 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8" ?>
<!--
Copyright 2020 Trey, Kilobytes de Soluciones
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
-->
<odoo>
<record id="view_delivery_carrier_form" model="ir.ui.view">
<field name="model">delivery.carrier</field>
<field name="inherit_id" ref="delivery.view_delivery_carrier_form"/>
<field name="inherit_id" ref="delivery.view_delivery_carrier_form" />
<field name="arch" type="xml">
<xpath expr="//field[@name='integration_level']" position="after">
<field name="price_method" attrs="{'invisible': [('delivery_type', 'in', ['fixed', 'base_on_rule'])], 'required': [('delivery_type', 'not in', ['fixed', 'base_on_rule'])]}"/>
<field
name="price_method"
attrs="{'invisible': [('delivery_type', 'in', ['fixed', 'base_on_rule'])], 'required': [('delivery_type', 'not in', ['fixed', 'base_on_rule'])]}"
/>
</xpath>
<xpath expr="(//page)[1]" position="before">
<page string="Pricing" attrs="{'invisible': [('delivery_type', 'in', ['fixed', 'base_on_rule'])]}">
<page
string="Pricing"
attrs="{'invisible': [('delivery_type', 'in', ['fixed', 'base_on_rule'])]}"
>
<group attrs="{'invisible':[('price_method', '!=', 'fixed')]}">
<group>
<field name="fixed_price"/>
<field name="fixed_price" />
</group>
</group>
<group name="general" attrs="{'invisible':[('price_method', '!=', 'base_on_rule')]}">
<field name="price_rule_ids" nolabel="1"/>
<group
name="general"
attrs="{'invisible':[('price_method', '!=', 'base_on_rule')]}"
>
<field name="price_rule_ids" nolabel="1" />
</group>
</page>
</xpath>