24 lines
998 B
Python
24 lines
998 B
Python
from odoo import models, fields, api, _
|
|
|
|
class SaleOrder(models.Model):
|
|
_inherit = 'sale.order'
|
|
|
|
def _add_uber_delivery_fee(self, amount):
|
|
"""Add the delivery fee as a line item if not already added or update it"""
|
|
config = self.env['uber.config'].sudo().search([('active', '=', True)], limit=1)
|
|
if config and config.delivery_product_id:
|
|
fee_product = config.delivery_product_id
|
|
# Check if fee line exists
|
|
fee_line = self.order_line.filtered(lambda l: l.product_id == fee_product)
|
|
if fee_line:
|
|
fee_line.write({'price_unit': amount})
|
|
else:
|
|
self.write({'order_line': [(0, 0, {
|
|
'product_id': fee_product.id,
|
|
'name': fee_product.name,
|
|
'price_unit': amount,
|
|
'product_uom_qty': 1,
|
|
'is_delivery': True, # Mark as delivery line if possible
|
|
})]})
|
|
return True
|