[IMP] web, website*: adaptation due to the new Sale module
Major changes: - No use of UoS anymore - Specific method to calculate delivery Reason: complete rewrite of the Sale module. Responsible: fp, dbo, nim
This commit is contained in:
@@ -784,7 +784,7 @@ odoo.define_section('eval.contexts', ['web.pyeval'], function (test) {
|
||||
"product_id": 4,
|
||||
"name": "[PC1] Basic PC",
|
||||
"quantity": 1,
|
||||
"uos_id": 1,
|
||||
"uom_id": 1,
|
||||
"price_unit": 100,
|
||||
"account_id": 853,
|
||||
"discount": 0,
|
||||
|
||||
@@ -18,16 +18,12 @@ class sale_order(osv.Model):
|
||||
domain += [('event_ticket_id', '=', context.get("event_ticket_id"))]
|
||||
return self.pool.get('sale.order.line').search(cr, SUPERUSER_ID, domain, context=context)
|
||||
|
||||
def _website_product_id_change(self, cr, uid, ids, order_id, product_id, qty=0, line_id=None, context=None):
|
||||
values = super(sale_order, self)._website_product_id_change(cr, uid, ids, order_id, product_id, qty=qty, line_id=line_id, context=None)
|
||||
def _website_product_id_change(self, cr, uid, ids, order_id, product_id, qty=0, context=None):
|
||||
values = super(sale_order, self)._website_product_id_change(cr, uid, ids, order_id, product_id, qty=qty, context=None)
|
||||
|
||||
event_ticket_id = None
|
||||
if context.get("event_ticket_id"):
|
||||
event_ticket_id = context.get("event_ticket_id")
|
||||
elif line_id:
|
||||
line = self.pool.get('sale.order.line').browse(cr, SUPERUSER_ID, line_id, context=context)
|
||||
if line.event_ticket_id:
|
||||
event_ticket_id = line.event_ticket_id.id
|
||||
else:
|
||||
product = self.pool.get('product.product').browse(cr, uid, product_id, context=context)
|
||||
if product.event_ticket_ids:
|
||||
@@ -59,6 +55,7 @@ class sale_order(osv.Model):
|
||||
line = OrderLine.browse(cr, uid, line_id, context=context)
|
||||
ticket = line.event_ticket_id
|
||||
old_qty = int(line.product_uom_qty)
|
||||
context = dict(context, event_ticket_id=ticket.id)
|
||||
else:
|
||||
line, ticket = None, None
|
||||
ticket_ids = Ticket.search(cr, uid, [('product_id', '=', product_id)], limit=1, context=context)
|
||||
|
||||
@@ -82,6 +82,10 @@ base.ready().done(function () {
|
||||
$("select[name='country_id']").val("21");
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "Check that the subtotal is 5500.0",
|
||||
element: '#order_total_untaxed .oe_currency_value:contains("5500.0")',
|
||||
},
|
||||
{
|
||||
title: "Select `Wire Transfer` payment method",
|
||||
element: '#payment_method label:has(img[title="Wire Transfer"]) input',
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
<field name="name">Laptop E5023</field>
|
||||
<field name="product_id" ref="product.product_product_25"/>
|
||||
<field name="product_uom_qty">3</field>
|
||||
<field name="product_uos_qty">3</field>
|
||||
<field name="product_uom" ref="product.product_uom_unit"/>
|
||||
<field name="price_unit">2950.00</field>
|
||||
</record>
|
||||
@@ -28,7 +27,6 @@
|
||||
<field name="name">Pen drive, 16GB</field>
|
||||
<field name="product_id" ref="product.product_product_30"/>
|
||||
<field name="product_uom_qty">5</field>
|
||||
<field name="product_uos_qty">5</field>
|
||||
<field name="product_uom" ref="product.product_uom_unit"/>
|
||||
<field name="price_unit">145.00</field>
|
||||
</record>
|
||||
@@ -38,7 +36,6 @@
|
||||
<field name="name">Headset USB</field>
|
||||
<field name="product_id" ref="product.product_product_33"/>
|
||||
<field name="product_uom_qty">2</field>
|
||||
<field name="product_uos_qty">2</field>
|
||||
<field name="product_uom" ref="product.product_uom_unit"/>
|
||||
<field name="price_unit">65.00</field>
|
||||
</record>
|
||||
@@ -49,7 +46,6 @@
|
||||
<field name="partner_shipping_id" ref="portal.partner_demo_portal"/>
|
||||
<field name="user_id" ref="base.user_root"/>
|
||||
<field name="pricelist_id" ref="product.list0"/>
|
||||
<field name="order_policy">manual</field>
|
||||
<field name="team_id" ref="sales_team.team_sales_department"/>
|
||||
<field name="date_order" eval="(DateTime.today() - relativedelta(months=1)).strftime('%Y-%m-%d %H:%M')"/>
|
||||
<field name="message_partner_ids" eval="[(4, ref('portal.partner_demo_portal'))]"/>
|
||||
@@ -60,7 +56,6 @@
|
||||
<field name="name">Service on demand</field>
|
||||
<field name="product_id" ref="product.product_product_1"/>
|
||||
<field name="product_uom_qty">24</field>
|
||||
<field name="product_uos_qty">24</field>
|
||||
<field name="product_uom" ref="product.product_uom_hour"/>
|
||||
<field name="price_unit">75.00</field>
|
||||
</record>
|
||||
@@ -70,7 +65,6 @@
|
||||
<field name="name">On Site Assistance</field>
|
||||
<field name="product_id" ref="product.product_product_2"/>
|
||||
<field name="product_uom_qty">30</field>
|
||||
<field name="product_uos_qty">30</field>
|
||||
<field name="product_uom" ref="product.product_uom_hour"/>
|
||||
<field name="price_unit">38.25</field>
|
||||
</record>
|
||||
|
||||
@@ -152,8 +152,6 @@ class sale_quote(http.Controller):
|
||||
'name': option.name,
|
||||
'order_id': order.id,
|
||||
'product_id' : option.product_id.id,
|
||||
'product_uos_qty': option.quantity,
|
||||
'product_uos': option.uom_id.id,
|
||||
'product_uom_qty': option.quantity,
|
||||
'product_uom': option.uom_id.id,
|
||||
'discount': option.discount,
|
||||
|
||||
@@ -10,7 +10,7 @@ OpenERP E-Commerce
|
||||
==================
|
||||
|
||||
""",
|
||||
'depends': ['sale', 'website_payment', 'website_mail', 'website_portal_sale', 'rating'],
|
||||
'depends': ['website', 'sale', 'payment', 'website_payment', 'website_portal_sale', 'website_mail', 'rating'],
|
||||
'data': [
|
||||
'data/data.xml',
|
||||
'data/web_planner_data.xml',
|
||||
|
||||
@@ -588,6 +588,8 @@ class website_sale(http.Controller):
|
||||
# create partner
|
||||
billing_info['team_id'] = request.website.salesteam_id.id
|
||||
partner_id = orm_partner.create(cr, SUPERUSER_ID, billing_info, context=context)
|
||||
order.write({'partner_id': partner_id, 'partner_invoice_id': partner_id})
|
||||
order_obj.onchange_partner_id(cr, SUPERUSER_ID, [order.id], context=context)
|
||||
|
||||
# create a new shipping partner
|
||||
if checkout.get('shipping_id') == -1:
|
||||
@@ -598,24 +600,12 @@ class website_sale(http.Controller):
|
||||
shipping_info['type'] = 'delivery'
|
||||
shipping_info['parent_id'] = partner_id
|
||||
checkout['shipping_id'] = orm_partner.create(cr, SUPERUSER_ID, shipping_info, context)
|
||||
order.write({'partner_shipping_id': checkout.get('shipping_id')})
|
||||
order_obj.onchange_partner_shipping_id(cr, SUPERUSER_ID, [order.id], context=context)
|
||||
|
||||
order_info = {
|
||||
'partner_id': partner_id,
|
||||
'message_partner_ids': [(4, partner_id), (3, request.website.partner_id.id)],
|
||||
'partner_invoice_id': partner_id,
|
||||
}
|
||||
order_info.update(order_obj.onchange_partner_id(cr, SUPERUSER_ID, [], partner_id, context=context)['value'])
|
||||
address_change = order_obj.onchange_delivery_id(cr, SUPERUSER_ID, [], order.company_id.id, partner_id,
|
||||
checkout.get('shipping_id'), None, context=context)['value']
|
||||
order_info.update(address_change)
|
||||
if address_change.get('fiscal_position_id'):
|
||||
fiscal_update = order_obj.onchange_fiscal_position(cr, SUPERUSER_ID, [], address_change['fiscal_position_id'],
|
||||
[(4, l.id) for l in order.order_line], context=None)['value']
|
||||
order_info.update(fiscal_update)
|
||||
|
||||
order_info.pop('user_id')
|
||||
order_info.update(partner_shipping_id=checkout.get('shipping_id') or partner_id)
|
||||
|
||||
order_obj.write(cr, SUPERUSER_ID, [order.id], order_info, context=context)
|
||||
|
||||
@http.route(['/shop/checkout'], type='http', auth="public", website=True)
|
||||
|
||||
@@ -49,32 +49,17 @@ class sale_order(osv.Model):
|
||||
domain += [('id', '=', line_id)]
|
||||
return self.pool.get('sale.order.line').search(cr, SUPERUSER_ID, domain, context=context)
|
||||
|
||||
def _website_product_id_change(self, cr, uid, ids, order_id, product_id, qty=0, line_id=None, context=None):
|
||||
so = self.pool.get('sale.order').browse(cr, uid, order_id, context=context)
|
||||
|
||||
values = self.pool.get('sale.order.line').product_id_change(
|
||||
cr, SUPERUSER_ID, [],
|
||||
pricelist=so.pricelist_id.id,
|
||||
product=product_id,
|
||||
partner_id=so.partner_id.id,
|
||||
fiscal_position_id=so.fiscal_position_id.id,
|
||||
qty=qty,
|
||||
context=context
|
||||
)['value']
|
||||
|
||||
if line_id:
|
||||
line = self.pool.get('sale.order.line').browse(cr, SUPERUSER_ID, line_id, context=context)
|
||||
values['name'] = line.name
|
||||
else:
|
||||
product = self.pool.get('product.product').browse(cr, uid, product_id, context=context)
|
||||
values['name'] = product.display_name
|
||||
if product.description_sale:
|
||||
values['name'] += '\n'+product.description_sale
|
||||
|
||||
values['product_id'] = product_id
|
||||
values['order_id'] = order_id
|
||||
if values.get('tax_id') is not None:
|
||||
values['tax_id'] = [(6, 0, values['tax_id'])]
|
||||
def _website_product_id_change(self, cr, uid, ids, order_id, product_id, qty=0, context=None):
|
||||
product = self.pool['product.product'].browse(cr, uid, product_id, context=context)
|
||||
values = {
|
||||
'product_id': product_id,
|
||||
'name': product.display_name,
|
||||
'product_uom_qty': qty,
|
||||
'order_id': order_id,
|
||||
'product_uom': product.uom_id.id,
|
||||
}
|
||||
if product.description_sale:
|
||||
values['name'] += '\n' + product.description_sale
|
||||
return values
|
||||
|
||||
def _cart_update(self, cr, uid, ids, product_id=None, line_id=None, add_qty=0, set_qty=0, context=None, **kwargs):
|
||||
@@ -95,6 +80,7 @@ class sale_order(osv.Model):
|
||||
if not line_id:
|
||||
values = self._website_product_id_change(cr, uid, ids, so.id, product_id, qty=1, context=context)
|
||||
line_id = sol.create(cr, SUPERUSER_ID, values, context=context)
|
||||
sol.product_id_change(cr, SUPERUSER_ID, [line_id], context=context)
|
||||
if add_qty:
|
||||
add_qty -= 1
|
||||
|
||||
@@ -109,7 +95,7 @@ class sale_order(osv.Model):
|
||||
sol.unlink(cr, SUPERUSER_ID, [line_id], context=context)
|
||||
else:
|
||||
# update line
|
||||
values = self._website_product_id_change(cr, uid, ids, so.id, product_id, qty=quantity, line_id=line_id, context=context)
|
||||
values = self._website_product_id_change(cr, uid, ids, so.id, product_id, qty=quantity, context=context)
|
||||
values['product_uom_qty'] = quantity
|
||||
sol.write(cr, SUPERUSER_ID, [line_id], values, context=context)
|
||||
|
||||
@@ -256,8 +242,8 @@ class website(orm.Model):
|
||||
'team_id': w.salesteam_id.id,
|
||||
}
|
||||
sale_order_id = sale_order_obj.create(cr, SUPERUSER_ID, values, context=context)
|
||||
values = sale_order_obj.onchange_partner_id(cr, SUPERUSER_ID, [], partner.id, context=context)['value']
|
||||
values.update({'user_id': salesperson_id or w.salesperson_id.id})
|
||||
sale_order_obj.onchange_partner_id(cr, SUPERUSER_ID, [sale_order_id], context=context)
|
||||
values = {'user_id': salesperson_id or w.salesperson_id.id}
|
||||
|
||||
sale_order_obj.write(cr, SUPERUSER_ID, [sale_order_id], values, context=context)
|
||||
request.session['sale_order_id'] = sale_order_id
|
||||
@@ -281,7 +267,7 @@ class website(orm.Model):
|
||||
flag_pricelist = True
|
||||
fiscal_position = sale_order.fiscal_position_id and sale_order.fiscal_position_id.id or False
|
||||
|
||||
values = sale_order_obj.onchange_partner_id(cr, SUPERUSER_ID, [sale_order_id], partner.id, context=context)['value']
|
||||
values = sale_order_obj.onchange_partner_id(cr, SUPERUSER_ID, [sale_order_id], context=context).get('value', {})
|
||||
if values.get('pricelist_id'):
|
||||
if values['pricelist_id'] != pricelist_id:
|
||||
values['pricelist_id'] = pricelist_id
|
||||
@@ -315,7 +301,6 @@ class website(orm.Model):
|
||||
# update the pricelist
|
||||
if update_pricelist:
|
||||
values = {'pricelist_id': pricelist_id}
|
||||
values.update(sale_order.onchange_pricelist_id(pricelist_id, None)['value'])
|
||||
sale_order.write(values)
|
||||
for line in sale_order.order_line:
|
||||
if line.exists():
|
||||
|
||||
@@ -22,17 +22,11 @@ class delivery_carrier(orm.Model):
|
||||
class SaleOrder(orm.Model):
|
||||
_inherit = 'sale.order'
|
||||
|
||||
def _amount_all_wrapper(self, cr, uid, ids, field_name, arg, context=None):
|
||||
""" Wrapper because of direct method passing as parameter for function fields """
|
||||
return self._amount_all(cr, uid, ids, field_name, arg, context=context)
|
||||
|
||||
def _amount_all(self, cr, uid, ids, field_name, arg, context=None):
|
||||
res = super(SaleOrder, self)._amount_all(cr, uid, ids, field_name, arg, context=context)
|
||||
currency_pool = self.pool.get('res.currency')
|
||||
def _amount_delivery(self, cr, uid, ids, field_name, arg, context=None):
|
||||
res = {}
|
||||
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_pool.round(cr, uid, currency, line_amount)
|
||||
res[order.id] = {}
|
||||
res[order.id]['amount_delivery'] = sum([line.price_subtotal for line in order.order_line if line.is_delivery])
|
||||
return res
|
||||
|
||||
def _has_delivery(self, cr, uid, ids, field_name, arg, context=None):
|
||||
@@ -52,7 +46,7 @@ class SaleOrder(orm.Model):
|
||||
|
||||
_columns = {
|
||||
'amount_delivery': fields.function(
|
||||
_amount_all_wrapper, type='float', digits=0,
|
||||
_amount_delivery, type='float', digits=0,
|
||||
string='Delivery Amount',
|
||||
store={
|
||||
'sale.order': (lambda self, cr, uid, ids, c={}: ids, ['order_line'], 10),
|
||||
|
||||
Reference in New Issue
Block a user