Skip to content
Draft
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
7 changes: 3 additions & 4 deletions addons/delivery/controllers/location_selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@


class LocationSelectorController(Controller):

@route('/delivery/set_pickup_location', type='jsonrpc', auth='user')
def delivery_set_pickup_location(self, order_id, pickup_location_data):
""" Fetch the order and set the pickup location on the current order.
"""Fetch the order and set the pickup location on the current order.

:param int order_id: The sales order, as a `sale.order` id.
:param str pickup_location_data: The JSON-formatted pickup location address.
Expand All @@ -18,7 +17,7 @@ def delivery_set_pickup_location(self, order_id, pickup_location_data):

@route('/delivery/get_pickup_locations', type='jsonrpc', auth='user')
def delivery_get_pickup_locations(self, order_id, zip_code=None):
""" Fetch the order and return the pickup locations close to a given zip code.
"""Fetch the order and return the pickup locations close to a given zip code.

Determine the country based on GeoIP or fallback on the order's delivery address' country.

Expand All @@ -30,7 +29,7 @@ def delivery_get_pickup_locations(self, order_id, zip_code=None):
order = request.env['sale.order'].browse(order_id)
if request.geoip.country_code:
country = request.env['res.country'].search(
[('code', '=', request.geoip.country_code)], limit=1,
[('code', '=', request.geoip.country_code)], limit=1
)
else:
country = order.partner_shipping_id.country_id
Expand Down
24 changes: 13 additions & 11 deletions addons/delivery/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from . import delivery_carrier
from . import delivery_price_rule
from . import delivery_zip_prefix
from . import ir_http
from . import ir_module_module
from . import payment_provider
from . import payment_transaction
from . import product_category
from . import res_partner
from . import sale_order
from . import sale_order_line
from . import (
delivery_carrier,
delivery_price_rule,
delivery_zip_prefix,
ir_http,
ir_module_module,
payment_provider,
payment_transaction,
product_category,
res_partner,
sale_order,
sale_order_line,
)
342 changes: 226 additions & 116 deletions addons/delivery/models/delivery_carrier.py

Large diffs are not rendered by default.

40 changes: 30 additions & 10 deletions addons/delivery/models/delivery_price_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from odoo import api, fields, models
from odoo.tools import format_amount


VARIABLE_SELECTION = [
('weight', "Weight"),
('volume', "Volume"),
Expand All @@ -18,7 +17,15 @@ class DeliveryPriceRule(models.Model):
_description = "Delivery Price Rules"
_order = 'sequence, list_price, id'

@api.depends('variable', 'operator', 'max_value', 'list_base_price', 'list_price', 'variable_factor', 'currency_id')
@api.depends(
'variable',
'operator',
'max_value',
'list_base_price',
'list_price',
'variable_factor',
'currency_id',
)
def _compute_name(self):
for rule in self:
name = 'if %s %s %.02f then' % (rule.variable, rule.operator, rule.max_value)
Expand All @@ -34,20 +41,33 @@ def _compute_name(self):
name = '%s %s times %s' % (name, price, rule.variable_factor)
else:
name = '%s fixed price %s plus %s times %s' % (
name, base_price, price, rule.variable_factor
name,
base_price,
price,
rule.variable_factor,
)
rule.name = name

name = fields.Char(compute='_compute_name')
sequence = fields.Integer(required=True, default=10)
carrier_id = fields.Many2one('delivery.carrier', 'Carrier', required=True, index=True, ondelete='cascade')
carrier_id = fields.Many2one(
comodel_name='delivery.carrier', ondelete='cascade', required=True, index=True
)
currency_id = fields.Many2one(related='carrier_id.currency_id')

variable = fields.Selection(selection=VARIABLE_SELECTION, required=True, default='quantity')
operator = fields.Selection([('==', '='), ('<=', '<='), ('<', '<'), ('>=', '>='), ('>', '>')], required=True, default='<=')
max_value = fields.Float('Maximum Value', required=True)
list_base_price = fields.Float(string='Sale Base Price', digits='Product Price', required=True, default=0.0)
list_price = fields.Float('Sale Price', digits='Product Price', required=True, default=0.0)
variable = fields.Selection(selection=VARIABLE_SELECTION, default='quantity', required=True)
operator = fields.Selection(
selection=[('==', '='), ('<=', '<='), ('<', '<'), ('>=', '>='), ('>', '>')],
default='<=',
required=True,
)
max_value = fields.Float(string="Maximum Value", required=True)
list_base_price = fields.Float(
string="Sale Base Price", digits='Product Price', default=0.0, required=True
)
list_price = fields.Float(
string="Sale Price", digits='Product Price', default=0.0, required=True
)
variable_factor = fields.Selection(
selection=VARIABLE_SELECTION, string="Variable Factor", required=True, default='weight'
selection=VARIABLE_SELECTION, default='weight', required=True
)
16 changes: 7 additions & 9 deletions addons/delivery/models/delivery_zip_prefix.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@


class DeliveryZipPrefix(models.Model):
""" Zip prefix that a delivery.carrier will deliver to. """
"""Zip prefix that a delivery.carrier will deliver to."""

_name = 'delivery.zip.prefix'
_description = 'Delivery Zip Prefix'
_description = "Delivery Zip Prefix"
_order = 'name, id'

name = fields.Char('Prefix', required=True)
name = fields.Char(string="Prefix", required=True)

@api.model_create_multi
def create(self, vals_list):
for vals in vals_list:
# we cannot easily convert a list of prefix names into upper to compare with partner zips
# later on, so let's ensure they are always upper
# we cannot easily convert a list of prefix names into upper to compare with partner
# zips later on, so let's ensure they are always upper
vals['name'] = vals['name'].upper()
return super().create(vals_list)

Expand All @@ -24,7 +25,4 @@ def write(self, vals):
vals['name'] = vals['name'].upper()
return super().write(vals)

_name_uniq = models.Constraint(
'unique (name)',
'Prefix already exists!',
)
_name_uniq = models.Constraint('unique (name)', "Prefix already exists!")
6 changes: 3 additions & 3 deletions addons/delivery/models/payment_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
class PaymentProvider(models.Model):
_inherit = 'payment.provider'

custom_mode = fields.Selection(selection_add=[('cash_on_delivery', 'Cash On Delivery')])
custom_mode = fields.Selection(selection_add=[('cash_on_delivery', "Cash On Delivery")])

# === CRUD METHODS === #

def _get_default_payment_method_codes(self):
""" Override of `payment` to return the default payment method codes. """
"""Override of `payment` to return the default payment method codes."""
self.ensure_one()
if self.custom_mode != 'cash_on_delivery':
return super()._get_default_payment_method_codes()
Expand All @@ -24,7 +24,7 @@ def _get_default_payment_method_codes(self):

@api.model
def _get_compatible_providers(self, *args, sale_order_id=None, report=None, **kwargs):
""" Override of payment to exclude COD providers if the delivery method doesn't match.
"""Override of payment to exclude COD providers if the delivery method doesn't match.

:param int sale_order_id: The sales order to be paid, if any, as a `sale.order` id.
:param dict report: The availability report.
Expand Down
10 changes: 5 additions & 5 deletions addons/delivery/models/payment_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ class PaymentTransaction(models.Model):
_inherit = 'payment.transaction'

def _post_process(self):
""" Override of `payment` to confirm orders with the cash_on_delivery payment method and
trigger a picking creation. """
"""Override of `payment` to confirm orders with the cash_on_delivery payment method and
trigger a picking creation."""
cod_pending_txs = self.filtered(
lambda tx: tx.provider_id.custom_mode == 'cash_on_delivery' and tx.state == 'pending'
)
cod_pending_txs.sale_order_ids.filtered(
lambda so: so.state == 'draft'
).with_context(send_email=True).action_confirm()
cod_pending_txs.sale_order_ids.filtered(lambda so: so.state == 'draft').with_context(
send_email=True
).action_confirm()
super()._post_process()
11 changes: 9 additions & 2 deletions addons/delivery/models/product_category.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ class ProductCategory(models.Model):

@api.ondelete(at_uninstall=False)
def _unlink_except_delivery_category(self):
delivery_category = self.env.ref('delivery.product_category_deliveries', raise_if_not_found=False)
delivery_category = self.env.ref(
'delivery.product_category_deliveries', raise_if_not_found=False
)
if delivery_category and delivery_category in self:
raise UserError(_("You cannot delete this product category as it is used on the products linked to delivery methods."))
raise UserError(
_(
"You cannot delete this product category as it is used on the products linked"
" to delivery methods."
)
)
7 changes: 6 additions & 1 deletion addons/delivery/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
class ResPartner(models.Model):
_inherit = 'res.partner'

property_delivery_carrier_id = fields.Many2one('delivery.carrier', company_dependent=True, string="Delivery Method", help="Used in sales orders.")
property_delivery_carrier_id = fields.Many2one(
string="Delivery Method",
help="Used in sales orders.",
comodel_name='delivery.carrier',
company_dependent=True,
)
is_pickup_location = fields.Boolean() # Whether it is a pickup point address.

def _get_delivery_address_domain(self):
Expand Down
Loading