##############################################################################
import time
-from openerp.osv import fields,osv
+
+from openerp.addons import decimal_precision
+from openerp.addons.sale.sale import sale_order as OriginalSaleOrder
+from openerp.osv import fields, osv
from openerp.tools.translate import _
+
class sale_order_line(osv.osv):
_inherit = 'sale.order.line'
+
_columns = {
- 'is_delivery':fields.boolean("Is a Delivery"),
+ 'is_delivery': fields.boolean("Is a Delivery"),
}
+
_defaults = {
'is_delivery': False
}
-class sale_order(osv.osv):
+
+class sale_order(osv.Model):
_inherit = 'sale.order'
+
+ def _amount_all(self, cr, uid, ids, field_name, arg, context=None):
+ res = super(sale_order, self)._amount_all(cr, uid, ids, field_name, arg, context=context)
+ Currency = self.pool.get('res.currency')
+ for order in self.browse(cr, uid, ids, context=context):
+ line_amount = sum([line.price_subtotal for line in order.order_line if line.is_delivery])
+ currency = order.pricelist_id.currency_id
+ res[order.id]['amount_delivery'] = Currency.round(cr, uid, currency, line_amount)
+ return res
+
+ def _get_order(self, cr, uid, ids, context=None):
+ result = {}
+ for line in self.pool.get('sale.order.line').browse(cr, uid, ids, context=context):
+ result[line.order_id.id] = True
+ return result.keys()
+
_columns = {
- 'carrier_id':fields.many2one("delivery.carrier", "Delivery Method", help="Complete this field if you plan to invoice the shipping based on picking."),
+ 'carrier_id': fields.many2one(
+ "delivery.carrier", string="Delivery Method",
+ help="Complete this field if you plan to invoice the shipping based on picking."),
+ 'amount_delivery': fields.function(
+ _amount_all, type='float', digits_compute=decimal_precision.get_precision('Account'), string='Delivery Amount',
+ store={
+ 'sale.order': (lambda self, cr, uid, ids, c={}: ids, ['order_line'], 10),
+ 'sale.order.line': (_get_order, ['price_unit', 'tax_id', 'discount', 'product_uom_qty'], 10),
+ },
+ multi='sums', help="The amount without tax.", track_visibility='always'
+ ),
}
def onchange_partner_id(self, cr, uid, ids, part, context=None):
return True
def delivery_set(self, cr, uid, ids, context=None):
- order_obj = self.pool.get('sale.order')
line_obj = self.pool.get('sale.order.line')
grid_obj = self.pool.get('delivery.grid')
carrier_obj = self.pool.get('delivery.carrier')
'product_uom': grid.carrier_id.product_id.uom_id.id,
'product_id': grid.carrier_id.product_id.id,
'price_unit': grid_obj.get_price(cr, uid, grid.id, order, time.strftime('%Y-%m-%d'), context),
- 'tax_id': [(6,0,taxes_ids)],
+ 'tax_id': [(6, 0, taxes_ids)],
'type': 'make_to_stock',
'is_delivery': True
})
- #remove the value of the carrier_id field on the sale order
- return self.write(cr, uid, ids, {'carrier_id': False}, context=context)
- #return {'type': 'ir.actions.act_window_close'} action reload?
-
-
-# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
-
+ # remove the value of the carrier_id field on the sale order
+ # TDE NOTE: why removing it ?? seems weird
+ # return self.write(cr, uid, ids, {'carrier_id': False}, context=context)
# alread a transaction: forward to confirmation
tx = context.get('website_sale_transaction')
if tx and not tx.state == 'draft':
- print 'embetatn'
- # return request.redirect('/shop/confirmation/%s' % order.id)
+ return request.redirect('/shop/confirmation/%s' % order.id)
partner_id = False
shipping_partner_id = False
from openerp import SUPERUSER_ID
from openerp.osv import osv, fields
-class sale_order(osv.Model):
+
+class SaleOrder(osv.Model):
_inherit = "sale.order"
_columns = {
}
def _get_website_data(self, cr, uid, order, context):
- return {}
+ return {
+ 'partner': order.partner_id.id,
+ 'order': order
+ }
def get_total_quantity(self, cr, uid, ids, context=None):
order = self.browse(cr, uid, ids[0], context=context)
return int(sum(l.product_uom_qty for l in (order.order_line or [])))
-class sale_order_line(osv.Model):
+class SaleOrderLine(osv.Model):
_inherit = "sale.order.line"
def _recalculate_product_values(self, cr, uid, ids, product_id=0, context=None):
+ # TDE FIXME: seems to be defined several times -> fix me ?
if context is None:
context = {}
user_obj = self.pool.get('res.users')
<col width="120"/>
</colgroup>
<thead>
- <tr style="border-top: 1px solid #000">
+ <tr style="border-top: 1px solid #000" id="order_total">
<th><h3>Total:</h3></th>
<th class="text-right">
<h3><t t-call="website_sale.total"/></h3>
</th>
</tr>
- <tr class="text-muted">
+ <tr class="text-muted" id="order_total_taxes">
<td><abbr title="Taxes may be updated after providing shipping address">Taxes:</abbr></td>
<td class="text-right">
<span t-field="website_sale_order.amount_tax" t-field-options='{
<col width="120"/>
</colgroup>
<thead>
- <tr style="border-top: 1px solid #000">
+ <tr style="border-top: 1px solid #000" id="order_total">
<th><h3>Total:</h3></th>
- <th class="text-right"><h3><span t-field="website_sale_order.amount_total" t-field-options='{
+ <th class="text-right">
+ <h3><span t-field="website_sale_order.amount_total" t-field-options='{
"widget": "monetary",
"display_currency": "website.pricelist_id.currency_id"
- }'/></h3></th>
+ }'/></h3>
+ </th>
</tr>
- <tr class="text-muted">
+ <tr class="text-muted" id="order_total_taxes">
<td>Taxes:</td>
<td class="text-right"><span t-field="website_sale_order.amount_tax" t-field-options='{
"widget": "monetary",
</div>
</div>
- <div class="js_payment mb64" t-if="acquirers" id="payment_method">
- <h3>Choose your payment method</h3>
+ <div class="js_payment mb64 row" t-if="acquirers" id="payment_method">
+ <h4>Choose your Payment Method</h4>
<div class="col-lg-5 col-sm-6">
<t t-foreach="acquirers or []" t-as="acquirer">
<label t-if="acquirer.button" class="oe_sale_acquirer_logo" style="display: block;">
import models
+import controllers
from openerp.osv import orm, fields
+
class delivery_carrier(orm.Model):
_inherit = 'delivery.carrier'
_columns = {
'website_published': True
}
-class sale_order(orm.Model):
+
+class SaleOrder(orm.Model):
_inherit = 'sale.order'
+
def _get_website_data(self, cr, uid, order, context=None):
+ """ Override to add delivery-related website data. """
+ values = super(SaleOrder, self)._get_website_data(cr, uid, order, context=context)
# We need a delivery only if we have stockable products
todo = False
for line in order.order_line:
- if line.product_id.type in ('consu','product'):
+ if line.product_id.type in ('consu', 'product'):
todo = True
- if not todo: return {'deliveries': []}
+ if not todo:
+ return values
carrier_obj = self.pool.get('delivery.carrier')
dids = carrier_obj.search(cr, uid, [], context=context)
deliveries = carrier_obj.browse(cr, uid, dids, context=context)
# By default, select the first carrier
- if not order.carrier_id and dids:
- self.pool.get('sale.order').write(cr, uid, [order.id], {'carrier_id': dids[0]}, context=context)
+ # if not order.carrier_id and dids:
+ # self.pool.get('sale.order').write(cr, uid, [order.id], {'carrier_id': dids[0]}, context=context)
# recompute delivery costs
self.pool.get('sale.order').delivery_set(cr, uid, [order.id], context=context)
- return {'deliveries': deliveries}
+ values['deliveries'] = deliveries
+ return values
// }
// });
+ // When choosing an delivery carrier, update the quotation and the acquirers
+ var $carrier = $("#delivery_carrier");
+ $carrier.find("input[name='delivery_type']").click(function (ev) {
+ var carrier_id = $(ev.currentTarget).val();
+ console.log('choosing carrier', carrier_id);
+ var link = $carrier.find('a');
+ link.attr('href', '/shop/payment?carrier_id=' + carrier_id)
+ });
+
});
<?xml version="1.0" encoding="utf-8"?>
<openerp>
- <data>
+<data>
<template id="delivery" name="Delivery Costs" inherit_id="website_sale.payment">
<xpath expr="//t[@t-set='head']" position="inside">
<script type="text/javascript" src="/website_sale_delivery/static/src/js/website_sale_delivery.js"></script>
</xpath>
- <xpath expr="//div[@id='payment_method']" position="before">
- <t t-if="len(deliveries)">
- <p>Choose Your Delivery method:</p>
- <ul class="list-unstyled">
- <li t-foreach="deliveries" t-as="delivery">
- <label>
- <input t-att-value="delivery.id" type="radio" name="delivery_type"/>
- <span t-field="delivery.name"/>
- <span class="badge" t-field="delivery.price"/>
- <!-- TODO: add monetary widget -->
- </label>
- </li>
- </ul>
- </t>
+ <xpath expr="//tr[@id='order_total_taxes']" position="after">
+ <tr class="text-muted" id="order_delivery">
+ <td><abbr title="Delivery will be updated after choosing a new delivery method">Delivery:</abbr></td>
+ <td class="text-right">
+ <span t-field="website_sale_order.amount_delivery" t-field-options='{
+ "widget": "monetary",
+ "display_currency": "website.pricelist_id.currency_id"
+ }'/>
+ </td>
+ </tr>
+ </xpath>
+ <xpath expr="//div[@id='payment_method']" position="before">
+ <div t-if="len(deliveries)" class="row" id="delivery_carrier">
+ <h4>Choose your Delivery Method</h4>
+ <div class="col-lg-5 col-sm-6">
+ <ul class="list-unstyled">
+ <li t-foreach="deliveries" t-as="delivery">
+ <label>
+ <input t-att-value="delivery.id" type="radio" name="delivery_type"
+ t-att-checked="website_sale_order.carrier_id and website_sale_order.carrier_id.id == delivery.id and 'checked' or False"/>
+ <span t-field="delivery.name"/>
+ <span class="badge" t-field="delivery.price"
+ t-field-options='{
+ "widget": "monetary",
+ "display_currency": "website.pricelist_id.currency_id"
+ }'/>
+ </label>
+ </li>
+ </ul>
+ </div>
+ <div class="col-lg-3 col-sm-3">
+ <a t-href="/shop/payment"><button class="btn btn-primary">Update</button></a>
+ </div>
+ </div>
</xpath>
</template>
- </data>
+</data>
</openerp>