[IMP] delivery: margin on shipping price

Allow users to define a percentage on shipping price, in order to cover
up differences between rating and shipping actual price.

Authors:
	Barad Mahendra <mba@openerp.com>
	Parth Mehta <pme@odoo.com>
This commit is contained in:
Parth Mehta
2016-02-26 11:37:35 +01:00
committed by Richard Mathot
parent 7f64a2ec24
commit 9aa351a9db
3 changed files with 19 additions and 7 deletions
+13 -6
View File
@@ -52,6 +52,11 @@ class DeliveryCarrier(models.Model):
fixed_price = fields.Float(compute='_compute_fixed_price', inverse='_set_product_fixed_price', store=True, string='Fixed Price',help="Keep empty if the pricing depends on the advanced pricing per destination")
shipping_enabled = fields.Boolean(string="Shipping enabled", default=True, help="Uncheck this box to disable package shipping while validating Delivery Orders")
prod_environment = fields.Boolean("Environment", help="Set to True if your credentials are certified for production.")
margin = fields.Integer(help='This percentage will be added to the shipping price.')
_sql_constraints = [
('margin_not_under_100_percent', 'CHECK (margin >= -100)', 'Margin cannot be lower than -100%'),
]
@api.one
def toggle_prod_environment(self):
@@ -99,24 +104,26 @@ class DeliveryCarrier(models.Model):
order = SaleOrder.browse(order_id)
if self.delivery_type not in ['fixed', 'base_on_rule']:
try:
self.price = self.get_shipping_price_from_so(order)[0]
computed_price = self.get_shipping_price_from_so(order)[0]
self.available = True
except UserError as e:
# No suitable delivery method found, probably configuration error
_logger.info("Carrier %s: %s, not found", self.name, e.name)
self.price = 0.0
computed_price = 0.0
else:
carrier = self.verify_carrier(order.partner_shipping_id)
if carrier:
try:
self.price = carrier.get_price_available(order)
computed_price = carrier.get_price_available(order)
self.available = True
except UserError, e:
except UserError as e:
# No suitable delivery method found, probably configuration error
_logger.info("Carrier %s: %s", carrier.name, e.name)
self.price = 0.0
computed_price = 0.0
else:
self.price = 0.0
computed_price = 0.0
self.price = computed_price * (1.0 + (float(self.margin) / 100.0))
# -------------------------- #
# API for external providers #
+2 -1
View File
@@ -65,7 +65,8 @@ class SaleOrder(models.Model):
if order.company_id.currency_id.id != order.pricelist_id.currency_id.id:
price_unit = order.company_id.currency_id.with_context(date=order.date_order).compute(price_unit, order.pricelist_id.currency_id)
order._create_delivery_line(carrier, price_unit)
final_price = price_unit * (1.0 + (float(self.carrier_id.margin) / 100.0))
order._create_delivery_line(carrier, final_price)
else:
raise UserError(_('No carrier set for this order.'))
+4
View File
@@ -63,6 +63,10 @@
<page string="Pricing">
<group>
<field name="delivery_type" widget="radio"/>
<label for="margin"/>
<div>
<field name="margin" class="oe_inline"/>%
</div>
</group>
<group attrs="{'invisible':[('delivery_type', '!=', 'fixed')]}">
<group>