diff --git a/addons/delivery/delivery.py b/addons/delivery/delivery.py index 94a21289925..0a0abc92259 100644 --- a/addons/delivery/delivery.py +++ b/addons/delivery/delivery.py @@ -61,16 +61,16 @@ class delivery_carrier(osv.osv): return res _columns = { - 'name': fields.char('Carrier', size=64, required=True), - 'partner_id': fields.many2one('res.partner', 'Carrier Partner', required=True), + 'name': fields.char('Delivery Method', size=64, required=True), + 'partner_id': fields.many2one('res.partner', 'Transport Company', required=True, help="The partner that is doing the delivery service."), 'product_id': fields.many2one('product.product', 'Delivery Product', required=True), 'grids_id': fields.one2many('delivery.grid', 'carrier_id', 'Delivery Grids'), 'price' : fields.function(get_price, string='Price'), 'active': fields.boolean('Active', help="If the active field is set to False, it will allow you to hide the delivery carrier without removing it."), - 'normal_price': fields.float('Normal Price'), - 'free_if_more_than': fields.boolean('Free If More Than'), - 'amount': fields.float('Amount'), - 'use_detailed_pricelist': fields.boolean('Use Detailed Pricelist'), + 'normal_price': fields.float('Normal Price', help="Keep empty if the pricing depends on the advanced pricing per destination"), + 'free_if_more_than': fields.boolean('Free If More Than', help="If the order is more expensive than a certain amount, the customer can benefit from a free shipping"), + 'amount': fields.float('Amount', help="Amount of the order to benefit from a free shipping, expressed in the company currency"), + 'use_detailed_pricelist': fields.boolean('Advanced Pricing per Destination', help="Check this box if you want to manage delivery prices that depends on the destination, the weight, the total of the order, etc."), 'pricelist_ids': fields.one2many('delivery.grid', 'carrier_id', 'Advanced Pricing'), } @@ -103,25 +103,32 @@ class delivery_carrier(osv.osv): grid_line_pool = self.pool.get('delivery.grid.line') grid_pool = self.pool.get('delivery.grid') for record in self.browse(cr, uid, ids, context=context): - grid_id = grid_pool.search(cr, uid, [('carrier_id', '=', record.id)], context=context) + grid_id = grid_pool.search(cr, uid, [('carrier_id', '=', record.id),('sequence','=',9999)], context=context) + + if grid_id and not (record.normal_price or record.free_if_more_than): + grid_pool.unlink(cr, uid, grid_id, context=context) + + if not (record.normal_price or record.free_if_more_than): + continue + if not grid_id: record_data = { - 'name': vals.get('name', False), + 'name': record.name, 'carrier_id': record.id, - 'seqeunce': 10, + 'sequence': 9999, } new_grid_id = grid_pool.create(cr, uid, record_data, context=context) grid_id = [new_grid_id] - #delete all existing grid lines - grid_lines = [line.id for line in grid_pool.browse(cr, uid, grid_id[0]).line_ids if line.type == 'price'] - grid_line_pool.unlink(cr, uid, grid_lines, context=context) + lines = grid_line_pool.search(cr, uid, [('grid_id','in',grid_id)], context=context) + if lines: + grid_line_pool.unlink(cr, uid, lines, context=context) #create the grid lines if record.free_if_more_than: data = { 'grid_id': grid_id and grid_id[0], - 'name': _('Free if more than %d') % record.amount, + 'name': _('Free if more than %.2f') % record.amount, 'type': 'price', 'operator': '>=', 'max_value': record.amount, @@ -217,7 +224,7 @@ class delivery_grid_line(osv.osv): _description = "Delivery Grid Line" _columns = { 'name': fields.char('Name', size=32, required=True), - 'grid_id': fields.many2one('delivery.grid', 'Grid',required=True), + 'grid_id': fields.many2one('delivery.grid', 'Grid',required=True, ondelete='cascade'), 'type': fields.selection([('weight','Weight'),('volume','Volume'),\ ('wv','Weight * Volume'), ('price','Price')],\ 'Variable', required=True), diff --git a/addons/delivery/delivery_view.xml b/addons/delivery/delivery_view.xml index 23147a2716f..4d92e6aa125 100644 --- a/addons/delivery/delivery_view.xml +++ b/addons/delivery/delivery_view.xml @@ -9,6 +9,7 @@ tree + @@ -21,15 +22,16 @@
+ - - - + + + - + @@ -37,7 +39,6 @@ - @@ -76,8 +77,8 @@ ir.actions.act_window delivery.carrier form - form,tree - Define the delivery methods you are using and their pricing in order to reinvoice the delivery costs when you are doing invoicing based on delivery orders + tree,form + Define your delivery methods and their pricing. The delivery costs can be added on the sale order form or in the invoice, based on the delivery orders.