[IMP] Cart Rules code modify, Change content of index file and misc changes.

This commit is contained in:
Haresh Chavda 2018-05-10 17:51:12 +05:30
parent 48e2689de5
commit 090136aef2
11 changed files with 368 additions and 103 deletions

View File

@ -2,7 +2,7 @@
# Part of flectra. See LICENSE file for full copyright and licensing details. # Part of flectra. See LICENSE file for full copyright and licensing details.
{ {
'name': 'Sale Advance Ecommerce Pricelist', 'name': 'Sale Advance Pricelist',
'version': '1.0.0', 'version': '1.0.0',
'category': 'Sale', 'category': 'Sale',
'author': 'FlectraHQ', 'author': 'FlectraHQ',

View File

@ -4,10 +4,10 @@
# #
msgid "" msgid ""
msgstr "" msgstr ""
"Project-Id-Version: Flectra Server 1.1\n" "Project-Id-Version: Flectra Server 1.2\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-04-12 05:50+0000\n" "POT-Creation-Date: 2018-05-14 05:17+0000\n"
"PO-Revision-Date: 2018-04-12 05:50+0000\n" "PO-Revision-Date: 2018-05-14 05:17+0000\n"
"Last-Translator: <>\n" "Last-Translator: <>\n"
"Language-Team: \n" "Language-Team: \n"
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
@ -52,13 +52,19 @@ msgstr "Advance Pricelist with All Matched Rule"
msgid "Advanced" msgid "Advanced"
msgstr "Advanced" msgstr "Advanced"
#. module: sale_advance_pricelist
#: code:addons/sale_advance_pricelist/models/price_rules.py:119
#, python-format
msgid "All Products"
msgstr "All Products"
#. module: sale_advance_pricelist #. module: sale_advance_pricelist
#: model:ir.model.fields,field_description:sale_advance_pricelist.field_cart_rule_amt_value #: model:ir.model.fields,field_description:sale_advance_pricelist.field_cart_rule_amt_value
msgid "Amount" msgid "Amount"
msgstr "Amount" msgstr "Amount"
#. module: sale_advance_pricelist #. module: sale_advance_pricelist
#: model:ir.ui.view,arch_db:sale_advance_pricelist.product_pricelist_view_flectra #: model:ir.ui.view,arch_db:sale_advance_pricelist.product_pricelist_view_advance
#: model:ir.ui.view,arch_db:sale_advance_pricelist.view_cart_rule_tree #: model:ir.ui.view,arch_db:sale_advance_pricelist.view_cart_rule_tree
#: model:ir.ui.view,arch_db:sale_advance_pricelist.view_coupon_code_tree #: model:ir.ui.view,arch_db:sale_advance_pricelist.view_coupon_code_tree
#: model:ir.ui.view,arch_db:sale_advance_pricelist.view_price_rule_tree #: model:ir.ui.view,arch_db:sale_advance_pricelist.view_price_rule_tree
@ -81,7 +87,7 @@ msgid "Apply Coupon"
msgstr "Apply Coupon" msgstr "Apply Coupon"
#. module: sale_advance_pricelist #. module: sale_advance_pricelist
#: model:ir.ui.view,arch_db:sale_advance_pricelist.view_order_form_flectra #: model:ir.ui.view,arch_db:sale_advance_pricelist.view_order_form_advance
msgid "Apply Coupon Code" msgid "Apply Coupon Code"
msgstr "Apply Coupon Code" msgstr "Apply Coupon Code"
@ -147,9 +153,16 @@ msgstr "Cart Discount"
msgid "Cart Rule" msgid "Cart Rule"
msgstr "Cart Rule" msgstr "Cart Rule"
#. module: sale_advance_pricelist
#. flectra-web
#: code:addons/sale_advance_pricelist/static/src/xml/discount_details_view.xml:80
#, python-format
msgid "Cart Rule (-):"
msgstr "Cart Rule (-):"
#. module: sale_advance_pricelist #. module: sale_advance_pricelist
#: model:ir.model,name:sale_advance_pricelist.model_cart_rule #: model:ir.model,name:sale_advance_pricelist.model_cart_rule
#: model:ir.ui.view,arch_db:sale_advance_pricelist.product_pricelist_view_flectra #: model:ir.ui.view,arch_db:sale_advance_pricelist.product_pricelist_view_advance
#: model:ir.ui.view,arch_db:sale_advance_pricelist.view_cart_rule_tree #: model:ir.ui.view,arch_db:sale_advance_pricelist.view_cart_rule_tree
msgid "Cart Rules" msgid "Cart Rules"
msgstr "Cart Rules" msgstr "Cart Rules"
@ -175,6 +188,12 @@ msgstr "Categories"
msgid "Category" msgid "Category"
msgstr "Category" msgstr "Category"
#. module: sale_advance_pricelist
#: code:addons/sale_advance_pricelist/models/price_rules.py:112
#, python-format
msgid "Category: %s"
msgstr "Category: %s"
#. module: sale_advance_pricelist #. module: sale_advance_pricelist
#: model:ir.model.fields,field_description:sale_advance_pricelist.field_sale_order_coupon_flag #: model:ir.model.fields,field_description:sale_advance_pricelist.field_sale_order_coupon_flag
msgid "Check Coupon Apply" msgid "Check Coupon Apply"
@ -202,10 +221,17 @@ msgstr "Coupon"
#. module: sale_advance_pricelist #. module: sale_advance_pricelist
#: model:ir.model,name:sale_advance_pricelist.model_coupon_code #: model:ir.model,name:sale_advance_pricelist.model_coupon_code
#: model:ir.model.fields,field_description:sale_advance_pricelist.field_coupon_code_coupon_code #: model:ir.model.fields,field_description:sale_advance_pricelist.field_coupon_code_coupon_code
#: model:ir.ui.view,arch_db:sale_advance_pricelist.product_pricelist_view_flectra #: model:ir.ui.view,arch_db:sale_advance_pricelist.product_pricelist_view_advance
msgid "Coupon Code" msgid "Coupon Code"
msgstr "Coupon Code" msgstr "Coupon Code"
#. module: sale_advance_pricelist
#. flectra-web
#: code:addons/sale_advance_pricelist/static/src/xml/discount_details_view.xml:92
#, python-format
msgid "Coupon Code (-):"
msgstr "Coupon Code (-):"
#. module: sale_advance_pricelist #. module: sale_advance_pricelist
#: model:ir.model.fields,field_description:sale_advance_pricelist.field_product_pricelist_coupon_code_lines #: model:ir.model.fields,field_description:sale_advance_pricelist.field_product_pricelist_coupon_code_lines
msgid "Coupon Code Items" msgid "Coupon Code Items"
@ -222,6 +248,37 @@ msgstr "Coupon Ref"
msgid "Coupon Type" msgid "Coupon Type"
msgstr "Coupon Type" msgstr "Coupon Type"
#. module: sale_advance_pricelist
#: code:addons/sale_advance_pricelist/models/sale.py:366
#, python-format
msgid "Coupon code (%s) Remaining Limit exceeds!"
msgstr "Coupon code (%s) Remaining Limit exceeds!"
#. module: sale_advance_pricelist
#: code:addons/sale_advance_pricelist/models/price_rules.py:388
#, python-format
msgid "Coupon code (%s) already exists!"
msgstr "Coupon code (%s) already exists!"
#. module: sale_advance_pricelist
#: code:addons/sale_advance_pricelist/models/sale.py:381
#: code:addons/sale_advance_pricelist/models/sale.py:468
#, python-format
msgid "Coupon code (%s) condition criteria not match!"
msgstr "Coupon code (%s) condition criteria not match!"
#. module: sale_advance_pricelist
#: code:addons/sale_advance_pricelist/models/sale.py:362
#, python-format
msgid "Coupon code (%s) not found!"
msgstr "Coupon code (%s) not found!"
#. module: sale_advance_pricelist
#: code:addons/sale_advance_pricelist/models/sale.py:356
#, python-format
msgid "Coupon code does not apply to sale order pricelist!"
msgstr "Coupon code does not apply to sale order pricelist!"
#. module: sale_advance_pricelist #. module: sale_advance_pricelist
#: model:ir.model.fields,field_description:sale_advance_pricelist.field_cart_rule_create_uid #: model:ir.model.fields,field_description:sale_advance_pricelist.field_cart_rule_create_uid
#: model:ir.model.fields,field_description:sale_advance_pricelist.field_coupon_code_create_uid #: model:ir.model.fields,field_description:sale_advance_pricelist.field_coupon_code_create_uid
@ -244,6 +301,12 @@ msgstr "Created on"
msgid "Description" msgid "Description"
msgstr "Description" msgstr "Description"
#. module: sale_advance_pricelist
#: code:addons/sale_advance_pricelist/models/sale.py:147
#, python-format
msgid "Discount"
msgstr "Discount"
#. module: sale_advance_pricelist #. module: sale_advance_pricelist
#: model:ir.model.fields,field_description:sale_advance_pricelist.field_cart_rule_discount_percentage #: model:ir.model.fields,field_description:sale_advance_pricelist.field_cart_rule_discount_percentage
#: model:ir.model.fields,field_description:sale_advance_pricelist.field_sale_order_line_dummy_discount #: model:ir.model.fields,field_description:sale_advance_pricelist.field_sale_order_line_dummy_discount
@ -266,6 +329,13 @@ msgstr "Discount Amount"
msgid "Discount Amount Words" msgid "Discount Amount Words"
msgstr "Discount Amount Words" msgstr "Discount Amount Words"
#. module: sale_advance_pricelist
#. flectra-web
#: code:addons/sale_advance_pricelist/static/src/xml/discount_details_view.xml:27
#, python-format
msgid "Discount Amount to Words:"
msgstr "Discount Amount to Words:"
#. module: sale_advance_pricelist #. module: sale_advance_pricelist
#: model:ir.model.fields,field_description:sale_advance_pricelist.field_sale_order_discount_widget #: model:ir.model.fields,field_description:sale_advance_pricelist.field_sale_order_discount_widget
msgid "Discount Widget" msgid "Discount Widget"
@ -293,6 +363,12 @@ msgstr "Domain"
msgid "End Date" msgid "End Date"
msgstr "End Date" msgstr "End Date"
#. module: sale_advance_pricelist
#: code:addons/sale_advance_pricelist/models/price_rules.py:98
#, python-format
msgid "End Date date not valid in Product Rule Lines!"
msgstr "End Date date not valid in Product Rule Lines!"
#. module: sale_advance_pricelist #. module: sale_advance_pricelist
#: model:ir.model.fields,field_description:sale_advance_pricelist.field_coupon_code_extra_discount_percentage #: model:ir.model.fields,field_description:sale_advance_pricelist.field_coupon_code_extra_discount_percentage
msgid "Extra Discount" msgid "Extra Discount"
@ -315,6 +391,13 @@ msgstr "Flat Discount"
msgid "Global" msgid "Global"
msgstr "Global" msgstr "Global"
#. module: sale_advance_pricelist
#. flectra-web
#: code:addons/sale_advance_pricelist/static/src/xml/discount_details_view.xml:44
#, python-format
msgid "Gross Amount:"
msgstr "Gross Amount:"
#. module: sale_advance_pricelist #. module: sale_advance_pricelist
#: model:ir.model.fields,field_description:sale_advance_pricelist.field_sale_order_have_coupon_code #: model:ir.model.fields,field_description:sale_advance_pricelist.field_sale_order_have_coupon_code
msgid "Have Coupon Code" msgid "Have Coupon Code"
@ -428,7 +511,21 @@ msgid "Percent"
msgstr "Percent" msgstr "Percent"
#. module: sale_advance_pricelist #. module: sale_advance_pricelist
#: model:ir.ui.view,arch_db:sale_advance_pricelist.product_pricelist_view_flectra #: code:addons/sale_advance_pricelist/models/price_rules.py:74
#: code:addons/sale_advance_pricelist/models/price_rules.py:217
#: code:addons/sale_advance_pricelist/models/price_rules.py:334
#, python-format
msgid "Percentage should be between 0% to 100%!"
msgstr "Percentage should be between 0% to 100%!"
#. module: sale_advance_pricelist
#: code:addons/sale_advance_pricelist/models/sale.py:351
#, python-format
msgid "Please enter the Coupon code!"
msgstr "Please enter the Coupon code!"
#. module: sale_advance_pricelist
#: model:ir.ui.view,arch_db:sale_advance_pricelist.product_pricelist_view_advance
msgid "Price" msgid "Price"
msgstr "Price" msgstr "Price"
@ -438,10 +535,17 @@ msgstr "Price"
msgid "Price Rule" msgid "Price Rule"
msgstr "Price Rule" msgstr "Price Rule"
#. module: sale_advance_pricelist
#. flectra-web
#: code:addons/sale_advance_pricelist/static/src/xml/discount_details_view.xml:68
#, python-format
msgid "Price Rule (-):"
msgstr "Price Rule (-):"
#. module: sale_advance_pricelist #. module: sale_advance_pricelist
#: model:ir.model,name:sale_advance_pricelist.model_price_rule #: model:ir.model,name:sale_advance_pricelist.model_price_rule
#: model:ir.model.fields,field_description:sale_advance_pricelist.field_product_pricelist_rule_ids #: model:ir.model.fields,field_description:sale_advance_pricelist.field_product_pricelist_rule_ids
#: model:ir.ui.view,arch_db:sale_advance_pricelist.product_pricelist_view_flectra #: model:ir.ui.view,arch_db:sale_advance_pricelist.product_pricelist_view_advance
#: model:ir.ui.view,arch_db:sale_advance_pricelist.view_price_rule_tree #: model:ir.ui.view,arch_db:sale_advance_pricelist.view_price_rule_tree
msgid "Price Rules" msgid "Price Rules"
msgstr "Price Rules" msgstr "Price Rules"
@ -456,7 +560,14 @@ msgid "Pricelist"
msgstr "Pricelist" msgstr "Pricelist"
#. module: sale_advance_pricelist #. module: sale_advance_pricelist
#: model:ir.ui.view,arch_db:sale_advance_pricelist.product_pricelist_view_flectra #. flectra-web
#: code:addons/sale_advance_pricelist/static/src/xml/discount_details_view.xml:56
#, python-format
msgid "Pricelist (-):"
msgstr "Pricelist (-):"
#. module: sale_advance_pricelist
#: model:ir.ui.view,arch_db:sale_advance_pricelist.product_pricelist_view_advance
msgid "Pricelist Items" msgid "Pricelist Items"
msgstr "Pricelist Items" msgstr "Pricelist Items"
@ -466,6 +577,7 @@ msgid "Pricelist Type"
msgstr "Pricelist Type" msgstr "Pricelist Type"
#. module: sale_advance_pricelist #. module: sale_advance_pricelist
#: model:ir.model,name:sale_advance_pricelist.model_product_product
#: model:ir.model.fields,field_description:sale_advance_pricelist.field_cart_rule_product_id #: model:ir.model.fields,field_description:sale_advance_pricelist.field_cart_rule_product_id
#: model:ir.model.fields,field_description:sale_advance_pricelist.field_coupon_code_product_id #: model:ir.model.fields,field_description:sale_advance_pricelist.field_coupon_code_product_id
#: model:ir.model.fields,field_description:sale_advance_pricelist.field_price_rule_product_id #: model:ir.model.fields,field_description:sale_advance_pricelist.field_price_rule_product_id
@ -521,7 +633,7 @@ msgid "Remaining Usage Limit"
msgstr "Remaining Usage Limit" msgstr "Remaining Usage Limit"
#. module: sale_advance_pricelist #. module: sale_advance_pricelist
#: model:ir.ui.view,arch_db:sale_advance_pricelist.view_order_form_flectra #: model:ir.ui.view,arch_db:sale_advance_pricelist.view_order_form_advance
msgid "Remove Coupon Code" msgid "Remove Coupon Code"
msgstr "Remove Coupon Code" msgstr "Remove Coupon Code"
@ -565,6 +677,12 @@ msgstr "Sequence"
msgid "Start Date" msgid "Start Date"
msgstr "Start Date" msgstr "Start Date"
#. module: sale_advance_pricelist
#: code:addons/sale_advance_pricelist/models/price_rules.py:92
#, python-format
msgid "Start Date date not valid in Product Rule Lines!"
msgstr "Start Date date not valid in Product Rule Lines!"
#. module: sale_advance_pricelist #. module: sale_advance_pricelist
#: selection:cart.rule,apply_on:0 #: selection:cart.rule,apply_on:0
msgid "Subtotal At Least" msgid "Subtotal At Least"
@ -585,11 +703,36 @@ msgstr "Sum of Item Qty at least"
msgid "Sum of Item Qty less than" msgid "Sum of Item Qty less than"
msgstr "Sum of Item Qty less than" msgstr "Sum of Item Qty less than"
#. module: sale_advance_pricelist
#: code:addons/sale_advance_pricelist/models/sale.py:353
#, python-format
msgid "There is no sale order line!"
msgstr "There is no sale order line!"
#. module: sale_advance_pricelist
#: code:addons/sale_advance_pricelist/models/price_rules.py:356
#, python-format
msgid "Total Percentage ( Discount + Extra ) should be between 0% to 100%!"
msgstr "Total Percentage ( Discount + Extra ) should be between 0% to 100%!"
#. module: sale_advance_pricelist #. module: sale_advance_pricelist
#: model:ir.model.fields,field_description:sale_advance_pricelist.field_coupon_code_usage_limit #: model:ir.model.fields,field_description:sale_advance_pricelist.field_coupon_code_usage_limit
msgid "Total Usage Limit" msgid "Total Usage Limit"
msgstr "Total Usage Limit" msgstr "Total Usage Limit"
#. module: sale_advance_pricelist
#: code:addons/sale_advance_pricelist/models/sale.py:371
#, python-format
msgid "Untaxed Amount (%s) must be greater than Min Order Amount (%s) which required for the apply coupon code!"
msgstr "Untaxed Amount (%s) must be greater than Min Order Amount (%s) which required for the apply coupon code!"
#. module: sale_advance_pricelist
#. flectra-web
#: code:addons/sale_advance_pricelist/static/src/xml/discount_details_view.xml:104
#, python-format
msgid "Untaxed Amount:"
msgstr "Untaxed Amount:"
#. module: sale_advance_pricelist #. module: sale_advance_pricelist
#: model:ir.model.fields,field_description:sale_advance_pricelist.field_coupon_code_code_valid_from #: model:ir.model.fields,field_description:sale_advance_pricelist.field_coupon_code_code_valid_from
msgid "Valid From" msgid "Valid From"
@ -600,6 +743,21 @@ msgstr "Valid From"
msgid "Valid To" msgid "Valid To"
msgstr "Valid To" msgstr "Valid To"
#. module: sale_advance_pricelist
#: code:addons/sale_advance_pricelist/models/price_rules.py:73
#: code:addons/sale_advance_pricelist/models/price_rules.py:216
#: code:addons/sale_advance_pricelist/models/price_rules.py:333
#: code:addons/sale_advance_pricelist/models/price_rules.py:355
#, python-format
msgid "Warning"
msgstr "Warning"
#. module: sale_advance_pricelist
#: code:addons/sale_advance_pricelist/models/sale.py:636
#, python-format
msgid "You can not change order line. Please remove coupon code first!"
msgstr "You can not change order line. Please remove coupon code first!"
#. module: sale_advance_pricelist #. module: sale_advance_pricelist
#: model:ir.model,name:sale_advance_pricelist.model_rule_line #: model:ir.model,name:sale_advance_pricelist.model_rule_line
msgid "rule.line" msgid "rule.line"

View File

@ -334,6 +334,17 @@ class CouponCode(models.Model):
'message': _("Percentage should be between 0% to 100%!")}) 'message': _("Percentage should be between 0% to 100%!")})
self.discount_amount = 0.0 self.discount_amount = 0.0
return {'warning': warning} return {'warning': warning}
if self.coupon_type not in ['percent', 'fixed_amount',
'buy_x_get_percent']:
self.discount_amount = 0.0
if self.coupon_type != 'clubbed':
self.flat_discount = 0.0
self.extra_discount_percentage = 0.0
if self.coupon_type not in ['buy_x_get_y', 'buy_x_get_y_other',
'buy_x_get_percent']:
self.number_of_x_product = 0.0
self.number_of_y_product = 0.0
self.other_product_id = False
@api.onchange('flat_discount', 'extra_discount_percentage') @api.onchange('flat_discount', 'extra_discount_percentage')
def check_clubbed_percentage(self): def check_clubbed_percentage(self):
@ -371,7 +382,8 @@ class CouponCode(models.Model):
def check_duplicate_coupon_code(self): def check_duplicate_coupon_code(self):
check_coupon_id = self.search([ check_coupon_id = self.search([
('coupon_code', '=', self.coupon_code), ('coupon_code', '=', self.coupon_code),
('id', '!=', self.id)]) ('id', '!=', self.id),
('pricelist_id', '=', self.pricelist_id.id)])
if check_coupon_id: if check_coupon_id:
raise Warning(_("Coupon code (%s) already exists!") % ( raise Warning(_("Coupon code (%s) already exists!") % (
self.coupon_code)) self.coupon_code))

View File

@ -4,6 +4,7 @@
from flectra import api, fields, models from flectra import api, fields, models
from flectra.exceptions import UserError from flectra.exceptions import UserError
from itertools import chain from itertools import chain
from flectra.tools import pycompat
class Pricelist(models.Model): class Pricelist(models.Model):
@ -30,17 +31,16 @@ class Pricelist(models.Model):
'coupon.code', 'pricelist_id', 'Coupon Code Items', 'coupon.code', 'pricelist_id', 'Coupon Code Items',
copy=True) copy=True)
def get_product_price_rule_flectra( def get_product_price_rule_advance(
self, product, quantity, partner, self, product, quantity, partner,
rule_id, price_unit, date=False, uom_id=False): date=False, uom_id=False):
self.ensure_one() self.ensure_one()
return self._compute_price_rule_flectra( return self._compute_price_rule_advance(
[(product, quantity, partner)], [(product, quantity, partner)],
rule_id, price_unit, date=date, uom_id=uom_id)[product.id] date=date, uom_id=uom_id)[product.id]
@api.multi @api.multi
def _compute_price_rule_flectra(self, products_qty_partner, def _compute_price_rule_advance(self, products_qty_partner,
rule_id, price_unit,
date=False, uom_id=False): date=False, uom_id=False):
self.ensure_one() self.ensure_one()
if not date: if not date:
@ -91,10 +91,9 @@ class Pricelist(models.Model):
'AND (item.pricelist_id = %s) ' 'AND (item.pricelist_id = %s) '
'AND (item.start_date IS NULL OR item.start_date<=%s) ' 'AND (item.start_date IS NULL OR item.start_date<=%s) '
'AND (item.end_date IS NULL OR item.end_date>=%s)' 'AND (item.end_date IS NULL OR item.end_date>=%s)'
'ORDER BY item.sequence,categ.parent_left desc', 'ORDER BY item.sequence,item.id,categ.parent_left desc',
(prod_tmpl_ids, rule_id.ids, prod_ids, (prod_tmpl_ids, self.rule_ids.ids, prod_ids,
categ_ids, self.id, date, date)) categ_ids, self.id, date, date))
item_ids = [x[0] for x in self._cr.fetchall()] item_ids = [x[0] for x in self._cr.fetchall()]
items = self.env['rule.line'].browse(item_ids) items = self.env['rule.line'].browse(item_ids)
results = {} results = {}
@ -156,9 +155,12 @@ class Pricelist(models.Model):
dis_price = 0.0 dis_price = 0.0
if price is not False: if price is not False:
if rule.rule_type == 'fixed_amount': if rule.rule_type == 'fixed_amount':
if price != price_unit: price_unit = self._context.get('price_unit')
if price_unit and price != price_unit \
and self.discount_policy == 'without_discount':
price = price_unit price = price_unit
if price < rule.discount_amount: if price <= rule.discount_amount \
and self.apply_method != 'smallest_discount':
price = 0 price = 0
suitable_rule = rule suitable_rule = rule
break break
@ -177,6 +179,14 @@ class Pricelist(models.Model):
min_dis_price.append(price - dis_price) min_dis_price.append(price - dis_price)
else: else:
max_dis_price.append(price - dis_price) max_dis_price.append(price - dis_price)
# Used context for add Cart Rules Discount
cart_price = 0.0
if self._context.get('order_id', False):
order_id = self._context.get('order_id')
cart_per = order_id.get_cart_rules_discount(
order_id.get_values())
cart_price = price * (cart_per / 100) or 0.0
if one_dis_price > 0.0: if one_dis_price > 0.0:
price = one_dis_price price = one_dis_price
elif all_dis_price > 0.0: elif all_dis_price > 0.0:
@ -185,8 +195,65 @@ class Pricelist(models.Model):
price = price - min(min_dis_price) price = price - min(min_dis_price)
elif max_dis_price: elif max_dis_price:
price = price - max(max_dis_price) price = price - max(max_dis_price)
if cart_price > 0.0:
price -= cart_price
price = product.currency_id.compute( price = product.currency_id.compute(
price, self.currency_id, round=False) price, self.currency_id, round=False)
results[product.id] = (price, results[product.id] = (price,
suitable_rule and suitable_rule.id or False) suitable_rule and suitable_rule.id or False)
return results return results
# Used context for add Cart Rules Discount
def get_products_price_advance(self, products, quantities,
partners, date=False, uom_id=False):
""" For a given pricelist, return price for products
Returns: dict{product_id: product price}, in the given pricelist """
self.ensure_one()
vals = {
product_id: res_tuple[0]
for product_id, res_tuple in self._compute_price_rule_advance(
list(pycompat.izip(products, quantities, partners)),
date=date, uom_id=uom_id).items()
}
return vals
class ProductProduct(models.Model):
_inherit = "product.product"
# Overrides Function
# Used context for add Cart Rules Discount
def _compute_product_price(self):
prices = {}
pricelist_id_or_name = self._context.get('pricelist')
if pricelist_id_or_name:
pricelist = None
partner = self._context.get('partner', False)
quantity = self._context.get('quantity', 1.0)
if isinstance(pricelist_id_or_name, pycompat.string_types):
pricelist_name_search = \
self.env['product.pricelist'].name_search(
pricelist_id_or_name, operator='=', limit=1)
if pricelist_name_search:
pricelist = \
self.env['product.pricelist'].browse(
[pricelist_name_search[0][0]])
elif isinstance(pricelist_id_or_name, pycompat.integer_types):
pricelist = self.env['product.pricelist'].browse(
pricelist_id_or_name)
if pricelist:
quantities = [quantity] * len(self)
partners = [partner] * len(self)
if pricelist.pricelist_type == 'basic':
prices = pricelist.get_products_price(
self, quantities, partners)
else:
prices = pricelist.with_context(
{'order_id': self._context.get('order_id')}
).get_products_price_advance(
self, quantities, partners)
for product in self:
product.price = prices.get(product.id, 0.0)
if self._context.get('order_id', False):
return product.price

View File

@ -25,19 +25,19 @@ class SaleOrder(models.Model):
for order in self: for order in self:
if order.pricelist_id.pricelist_type == 'advance': if order.pricelist_id.pricelist_type == 'advance':
order._update_all() order._update_all()
if order.pricelist_id.discount_policy == 'without_discount':
cart_discount = 0.0 cart_discount = 0.0
cart_discount_per = \ cart_discount_per = \
order.get_cart_rules_discount(order.get_values()) order.get_cart_rules_discount(order.get_values())
if order.pricelist_id.discount_policy == 'without_discount':
for line in order.order_line: for line in order.order_line:
if line.get_line_percentage(cart_discount_per) < 100: if line.get_line_percentage() < 100:
cart_discount += \ cart_discount += \
((line.price_unit * line.product_uom_qty ((line.price_unit * line.product_uom_qty
) * cart_discount_per) / 100 ) * cart_discount_per) / 100
order.cart_discount = cart_discount order.cart_discount = cart_discount
else: else:
for line in order.order_line: for line in order.order_line:
line.set_line_amount(cart_discount_per) line.set_line_amount()
@api.multi @api.multi
def get_cart_discount(self, cart_rule_id, values): def get_cart_discount(self, cart_rule_id, values):
@ -191,13 +191,23 @@ class SaleOrder(models.Model):
coupon_discount_amount = 0.0 coupon_discount_amount = 0.0
total_price = (line.product_uom_qty * line.price_unit) total_price = (line.product_uom_qty * line.price_unit)
if self.coupon_flag and not onchange_context and line.coupon_code_id: if self.coupon_flag and not onchange_context and line.coupon_code_id:
if line.dummy_discount:
percent = line.dummy_discount - discount_per
else:
percent = line.discount - discount_per
line.write({'check_coupon': False, line.write({'check_coupon': False,
'discount': line.discount - discount_per, 'discount': percent,
'coupon_code_id': False, 'coupon_code_id': False,
'check_coupon': False}) 'check_coupon': False})
elif not cal_coupon and not remove: elif not cal_coupon and not remove:
coupon_discount_amount = (total_price * discount_per) / 100 coupon_discount_amount = (total_price * discount_per) / 100
line.discount = line.discount + discount_per percent = line.discount + discount_per
if percent > 100:
line.dummy_discount = percent
line.discount = 100
else:
line.discount = percent
line.dummy_discount = 0.0
line.coupon_code_id = coupon_code_id.id line.coupon_code_id = coupon_code_id.id
line.check_coupon = True line.check_coupon = True
else: else:
@ -306,17 +316,26 @@ class SaleOrder(models.Model):
coupon_discount_amount = 0.0 coupon_discount_amount = 0.0
total_price = (line.product_uom_qty * line.price_unit) total_price = (line.product_uom_qty * line.price_unit)
if self.coupon_flag and not onchange_context and line.coupon_code_id \ if self.coupon_flag and not onchange_context and line.coupon_code_id \
and line.product_uom_qty > coupon_code_id.number_of_x_product: and line.product_uom_qty >= coupon_code_id.number_of_x_product:
if line.dummy_discount:
percent = line.dummy_discount - coupon_code_id.discount_amount
else:
percent = line.discount - coupon_code_id.discount_amount
line.write({'check_coupon': False, line.write({'check_coupon': False,
'discount': 'discount': percent,
line.discount - coupon_code_id.discount_amount,
'coupon_code_id': False, 'coupon_code_id': False,
'check_coupon': False}) 'check_coupon': False})
elif not cal_coupon and not remove and line.product_uom_qty >= \ elif not cal_coupon and not remove and line.product_uom_qty >= \
coupon_code_id.number_of_x_product: coupon_code_id.number_of_x_product:
coupon_discount_amount = \ coupon_discount_amount = \
(total_price * coupon_code_id.discount_amount) / 100 (total_price * coupon_code_id.discount_amount) / 100
line.discount = line.discount + coupon_code_id.discount_amount percent = line.discount + coupon_code_id.discount_amount
if percent > 100:
line.dummy_discount = percent
line.discount = 100
else:
line.discount = percent
line.dummy_discount = 0.0
line.coupon_code_id = coupon_code_id.id line.coupon_code_id = coupon_code_id.id
line.check_coupon = True line.check_coupon = True
else: else:
@ -365,6 +384,11 @@ class SaleOrder(models.Model):
@api.multi @api.multi
def apply_coupon_code(self): def apply_coupon_code(self):
if self._context.get('website_id', False):
coupon_obj = self.env['coupon.code']
coupon_id = coupon_obj.get_coupon_records(
self.have_coupon_code, self.pricelist_id)
else:
coupon_id = self._check_Constraints() coupon_id = self._check_Constraints()
order_line = self.order_line order_line = self.order_line
coupon_discount_amount = 0.0 coupon_discount_amount = 0.0
@ -440,7 +464,7 @@ class SaleOrder(models.Model):
line, coupon_id, onchange_context, line, coupon_id, onchange_context,
cal_coupon, remove) cal_coupon, remove)
check_coupon = False check_coupon = False
if check_coupon: if check_coupon and not self._context.get('website_id', False):
raise Warning(_("Coupon code (%s) condition criteria not match!" raise Warning(_("Coupon code (%s) condition criteria not match!"
) % (self.have_coupon_code)) ) % (self.have_coupon_code))
if qty: if qty:
@ -463,9 +487,9 @@ class SaleOrderLine(models.Model):
digits=dp.get_precision('Discount'), default=0.0) digits=dp.get_precision('Discount'), default=0.0)
@api.multi @api.multi
def get_line_percentage(self, percent): def get_line_percentage(self):
self._onchange_discount() self._onchange_discount()
discount = self.discount + percent discount = self.discount
if discount > 100: if discount > 100:
self.dummy_discount = discount self.dummy_discount = discount
discount = 100 discount = 100
@ -473,17 +497,17 @@ class SaleOrderLine(models.Model):
return discount return discount
@api.multi @api.multi
def set_line_amount(self, percent): def set_line_amount(self):
discount, product_price = self.get_rule_discount() discount, product_price = self.get_rule_discount()
if product_price: if product_price:
discount = product_price * (discount + percent) / 100 discount = product_price * (discount) / 100
self.price_unit = product_price - discount self.price_unit = product_price - discount
@api.multi @api.multi
def get_total_coupon_code(self): def get_total_coupon_code(self):
return self.env['coupon.code'].get_coupon_discount(self, False) return self.env['coupon.code'].get_coupon_discount(self, False)
def _get_real_price_currency_flectra(self, product, uom, def _get_real_price_currency_advance(self, product, uom,
pricelist_id, price_unit): pricelist_id, price_unit):
currency_id = pricelist_id.currency_id currency_id = pricelist_id.currency_id
product_currency = \ product_currency = \
@ -514,20 +538,20 @@ class SaleOrderLine(models.Model):
context_partner = dict(self.env.context, context_partner = dict(self.env.context,
partner_id=self.order_id.partner_id.id, partner_id=self.order_id.partner_id.id,
date=self.order_id.date_order) date=self.order_id.date_order)
pricelist_context = dict(context_partner, uom=self.product_uom.id) pricelist_context = dict(context_partner, uom=self.product_uom.id,
order_id=self.order_id,
price_unit=self.price_unit)
product_price = 0.0 product_price = 0.0
for rule in rules: for rule in rules:
adv_price, adv_rule_id = \ adv_price, adv_rule_id = \
self.order_id.pricelist_id.with_context( self.order_id.pricelist_id.with_context(
pricelist_context).get_product_price_rule_flectra( pricelist_context).get_product_price_rule_advance(
self.product_id, self.product_uom_qty, self.product_id, self.product_uom_qty,
self.order_id.partner_id, rule, self.price_unit) self.order_id.partner_id)
rule_line_id = self.env['rule.line'].browse(adv_rule_id) rule_line_id = self.env['rule.line'].browse(adv_rule_id)
if not rule_line_id:
return discount, product_price
adv_new_price = 0.0 adv_new_price = 0.0
currency_id = False currency_id = False
if rule_line_id.rule_type == 'percent': if not rule_line_id:
adv_new_price, currency_id = self.with_context( adv_new_price, currency_id = self.with_context(
context_partner)._get_real_price_currency( context_partner)._get_real_price_currency(
self.product_id, False, self.product_id, False,
@ -535,8 +559,16 @@ class SaleOrderLine(models.Model):
self.product_uom, self.product_uom,
self.order_id.pricelist_id.id) self.order_id.pricelist_id.id)
else: else:
if rule_line_id.rule_type == 'percent':
adv_new_price, currency_id = self.with_context( adv_new_price, currency_id = self.with_context(
context_partner)._get_real_price_currency_flectra( context_partner)._get_real_price_currency(
self.product_id, False,
self.product_uom_qty,
self.product_uom,
self.order_id.pricelist_id.id)
elif rule_line_id.rule_type == 'fixed_amount':
adv_new_price, currency_id = self.with_context(
context_partner)._get_real_price_currency_advance(
self.product_id, self.product_id,
self.product_uom, self.product_uom,
self.order_id.pricelist_id, self.price_unit) self.order_id.pricelist_id, self.price_unit)

View File

@ -7,3 +7,7 @@ access_rule_line_manager,access_rule_line_manager,model_rule_line,base.group_par
access_price_rule_manager,access_price_rule_manager,model_price_rule,base.group_partner_manager,1,0,0,0 access_price_rule_manager,access_price_rule_manager,model_price_rule,base.group_partner_manager,1,0,0,0
access_cart_rule_manager,access_cart_rule_manager,model_cart_rule,base.group_partner_manager,1,0,0,0 access_cart_rule_manager,access_cart_rule_manager,model_cart_rule,base.group_partner_manager,1,0,0,0
access_coupon_code_manager,access_coupon_code_manager,model_coupon_code,base.group_partner_manager,1,0,0,0 access_coupon_code_manager,access_coupon_code_manager,model_coupon_code,base.group_partner_manager,1,0,0,0
access_rule_line_public,access_rule_line_public,model_rule_line,,1,0,0,0
access_price_rule_public,access_price_rule_public,model_price_rule,,1,0,0,0
access_cart_rule_public,access_cart_rule_public,model_cart_rule,,1,0,0,0
access_coupon_code_public,access_coupon_code_public,model_coupon_code,,1,0,0,0

1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
7 access_price_rule_manager access_price_rule_manager model_price_rule base.group_partner_manager 1 0 0 0
8 access_cart_rule_manager access_cart_rule_manager model_cart_rule base.group_partner_manager 1 0 0 0
9 access_coupon_code_manager access_coupon_code_manager model_coupon_code base.group_partner_manager 1 0 0 0
10 access_rule_line_public access_rule_line_public model_rule_line 1 0 0 0
11 access_price_rule_public access_price_rule_public model_price_rule 1 0 0 0
12 access_cart_rule_public access_cart_rule_public model_cart_rule 1 0 0 0
13 access_coupon_code_public access_coupon_code_public model_coupon_code 1 0 0 0

View File

@ -13,19 +13,19 @@
<div class="oe_demo oe_picture oe_screenshot"> <div class="oe_demo oe_picture oe_screenshot">
<p class="mt32 text-justify"> <p class="mt32 text-justify">
<h4>- Add new option Pricelist Type (Basic, Advanced).</h4></br> <h4>- Add new option Pricelist Type (Basic, Advanced).</h4></br>
<h4>- Apply Method :-</h4></br> <h4>- Apply Method:</h4></br>
<UL> <UL>
<li> <b>Apply First Matched Rules</b> (Calculate discount of first match condition of Price Rules and Cart Rules)</li> <li> <b>Apply First Matched Rules</b> (Calculate discount of first match condition of Price Rules and Cart Rules)</li>
<li> <b>Apply All Matched Rules</b> (Calculate discount of all match condition of Price Rules and Cart Rules)</li> <li> <b>Apply All Matched Rules</b> (Calculate discount of all match condition of Price Rules and Cart Rules)</li>
<li> <b>Apply Smallest Matched Discount</b> (Append minimum discount of every match condition of Price Rules and Cart Rules and get minimum values from the list of Price Rules and Cart Rules)</li> <li> <b>Apply Smallest Matched Discount</b> (Append minimum discount of every match condition of Price Rules and Cart Rules and get minimum values from the list of Price Rules and Cart Rules)</li>
<li> <b>Apply Biggest Matched Discount</b> (Append maximum discount of every match condition of Price Rules and Cart Rules and get maximum values from the list of Price Rules and Cart Rules)</li> <li> <b>Apply Biggest Matched Discount</b> (Append maximum discount of every match condition of Price Rules and Cart Rules and get maximum values from the list of Price Rules and Cart Rules)</li>
</UL> </UL>
<h4> Price Rules applicable on the selected option:-</h4> <h4> Price Rules applicable to the selected option:-</h4>
<ul> <ul>
<li><b>Global: </b> Apply for all Product.</li> <li><b>Global: </b> Apply for all Product.</li>
<li><b>Category: </b> Apply only for selected category.</li> <li><b>Category: </b> Apply only for the selected category.</li>
<li><b>Product Template: </b>Apply only for selected Product Template variants.</li> <li><b>Product Template: </b>Apply only for selected Product Template variants.</li>
<li><b>Product Variant:</b>Apply only for selected Product variants.</li> <li><b>Product Variant: </b>Apply only for selected Product variants.</li>
</ul> </ul>
<h4>- Product Rules Line:-</h4></br> <h4>- Product Rules Line:-</h4></br>
<ul> <li>Discount applicable based on match condition which defines in Product Rules Line.</li></ul> <ul> <li>Discount applicable based on match condition which defines in Product Rules Line.</li></ul>
@ -48,18 +48,18 @@
<div class="row oe_spaced"> <div class="row oe_spaced">
<div class="oe_demo oe_picture oe_screenshot"> <div class="oe_demo oe_picture oe_screenshot">
<p class="mt32 text-justify"> <p class="mt32 text-justify">
<h4>- Apply On :-</h4></br> <h4>- Apply On:</h4></br>
<UL> <UL>
<li> <b>Subtotal At Least :-</b> Cart Rules not apply if Untaxed Amount is less than define amount in cart line.</li> <li> <b>Subtotal At Least:</b> Cart Rules do not apply if Untaxed Amount is less than define amount in cart line.</li>
<li> <b>Subtotal less than :-</b> Cart Rules apply if Untaxed Amount is less than define amount in cart line.</li> <li> <b>Subtotal less than:</b> Cart Rules apply if Untaxed Amount is less than define amount in cart line.</li>
<li> <b>Lines Count at least :-</b> Cart Rules not apply if line count of sale order(duplicate product exclude) is less than define amount in cart line.</li> <li> <b>Lines Count at least:</b> Cart Rules not apply if line count of sale order(duplicate product exclude) is less than define amount in cart line.</li>
<li> <b>Lines less than :-</b> Cart Rules apply if line count of sale order(duplicate product exclude) is less than define amount in cart line.</li> <li> <b>Lines less than:</b> Cart Rules apply if line count of sale order(duplicate product exclude) is less than define amount in cart line.</li>
<li> <b>Sum of Item Qty at least :-</b> Cart Rules is not apply if total quantity of product in sale order is less than define amount in cart line.</li> <li> <b>Sum of Item Qty at least:</b> Cart Rules is do not apply if the total quantity of product in sale order is less than define amount in cart line.</li>
<li> <b>Sum of Item Qty less than :-</b> Cart Rules apply if the total quantity of product in sale order is less than define amount in cart line.</li> <li> <b>Sum of Item Qty less than:</b> Cart Rules apply if the total quantity of product in sale order is less than define amount in cart line.</li>
<li> <b>At least one product in order :-</b> Cart Rules apply if product match in sale order which defines in cart line.</li> <li> <b>At least one product in order:</b> Cart Rules apply if product match in sale order which defines in cart line.</li>
<li> <b>None of selected Products :-</b> Cart Rules do not apply if product match in sale order which defines in cart line.</li> <li> <b>None of selected Products:</b> Cart Rules do not apply if product match in sale order which defines in cart line.</li>
<li> <b>At least one category in order :-</b> Cart Rules apply if product category match in sale order which defines in cart line.</li> <li> <b>At least one category in order:</b> Cart Rules apply if product category match in sale order which defines in cart line.</li>
<li> <b>None of selected Categories :-</b> Cart Rules do not apply if product category match in sale order which defines in cart line.</li> <li> <b>None of selected Categories:</b> Cart Rules do not apply if product category match in sale order which defines in cart line.</li>
</UL> </UL>
</p> </p>
</div> </div>
@ -80,15 +80,15 @@
<div class="row oe_spaced"> <div class="row oe_spaced">
<div class="oe_demo oe_picture oe_screenshot"> <div class="oe_demo oe_picture oe_screenshot">
<p class="mt32 text-justify"> <p class="mt32 text-justify">
<h4>- Apply Coupon Code:</h4> Select apply coupon code option in pricelist for apply coupon code.</br> <h4>- Apply Coupon Code:</h4> Select apply coupon code option in pricelist for the apply coupon code.</br>
<h4>- Coupon Type:</h4> <h4>- Coupon Type:</h4>
<UL> <UL>
<li> <b>Percent :-</b> Add Percentage in sale order line which defines in Discount Amount.</li> <li> <b>Percent:</b> Add Percentage in sale order line which defines in Discount Amount.</li>
<li> <b>Fixed Amount :-</b> Convert fixed amount values in percentage based on the unit price of sale order line.</li> <li> <b>Fixed Amount:</b> Convert fixed amount values in percentage based on the unit price of sale order line.</li>
<li> <b>Buy X Product Get Y Product Free :-</b> Get Y same product unit free when buying X product.</li> <li> <b>Buy X Product Get Y Product Free:</b> Get Y same product unit free when buying X product.</li>
<li> <b>Buy X Product Get Y Other Product Free :-</b> Get Y other product(which define in coupon code) unit free when buying X product.</li> <li> <b>Buy X Product Get Y Other Product Free:</b> Get Y other product(which define in coupon code) unit free when buying X product.</li>
<li> <b>Range Based Discount(Buy X Product Get Percent Free) :-</b> Get percent free(which define in coupon code) when buying X product.</li> <li> <b>Range Based Discount(Buy X Product Get Percent Free):</b> Get percent free(which define in coupon code) when buying X product.</li>
<li> <b>Clubbed Discount :-</b> Add Discount and Extra Discount on Sale order line.</li> <li> <b>Clubbed Discount:</b> Add Discount and Extra Discount on Sale order line.</li>
</UL> </UL>
</p> </p>
</div> </div>
@ -129,28 +129,28 @@
<div class="row oe_spaced"> <div class="row oe_spaced">
<div class="col-md-6"> <div class="col-md-6">
<p class="mt32 mb32 text-justify"> <p class="mt32 mb32 text-justify">
<h4>First order line discount caculation:</h4> </br> <h4>First order line discount calculation:</h4> </br>
<p style="margin-left: 20px;">First order line quantity 5 is between 1 to 5 in Product Rule Line.</p> <p style="margin-left: 20px;">First order line quantity 5 is between 1 to 5 in Product Rule Line.</p>
<p style="margin-left: 20px;">Here define fixed amount = 50 in match Product Rule Line.</p> <p style="margin-left: 20px;">Here define fixed amount = 50 in match Product Rule Line.</p>
<p style="margin-left: 20px;">Percentage Formule = Discount Amount * 100 / Unit Price</p> <p style="margin-left: 20px;">Percentage Formule = Discount Amount * 100 / Unit Price</p>
<p style="margin-left: 20px;">50 * 100 / 885 = 5.65</p> <p style="margin-left: 20px;">50 * 100 / 885 = 5.65</p>
<p style="margin-left: 20px;">6.5 % of Match first Cart Rules beacuse Subtotal(Untaxed Amount) At Least : 2,500.00.</p> <p style="margin-left: 20px;">6.5 % of Match first Cart Rules because Subtotal(Untaxed Amount) At Least: 2,500.00.</p>
<p style="margin-left: 20px;">Discount Formula= <b> Product Rule line + Cart Rules</b></p> <p style="margin-left: 20px;">Discount Formula= <b> Product Rule line + Cart Rules</b></p>
<p style="margin-left: 20px;">so discount is <b>5.65 + 6.5 = 12.15%</b></p> <p style="margin-left: 20px;">so discount is <b>5.65 + 6.5 = 12.15%</b></p>
</p> </p>
</div> </div>
<div class="col-md-6"> <div class="col-md-6">
<p class="mt32 mb32 text-justify"> <p class="mt32 mb32 text-justify">
<h4> Second order line discount caculation:</h4> </br> <h4> Second order line discount calculation:</h4> </br>
<p style="margin-left: 20px;">Second order line quantity 3 is between 1 to 5 in Product Rule Line.</p> <p style="margin-left: 20px;">Second order line quantity 3 is between 1 to 5 in Product Rule Line.</p>
<p style="margin-left: 20px;">Discount = Discount Amount * 100 / Unit Price</p> <p style="margin-left: 20px;">Discount = Discount Amount * 100 / Unit Price</p>
<p style="margin-left: 20px;">50 * 100 / 2950 = 1.69</p> <p style="margin-left: 20px;">50 * 100 / 2950 = 1.69</p>
<p style="margin-left: 20px;">6.5 % of Match first Cart Rules beacuse Subtotal(Untaxed Amount) At Least : 2,500.00.</p> <p style="margin-left: 20px;">6.5 % of Match first Cart Rules because Subtotal(Untaxed Amount) At Least: 2,500.00.</p>
<p style="margin-left: 20px;">so discount is <b> 1.69 + 6.5 = 8.19%</b></p> <p style="margin-left: 20px;">so discount is <b> 1.69 + 6.5 = 8.19%</b></p>
<h4> Third order line discount caculation:</h4> </br> <h4> Third order line discount calculation:</h4> </br>
<p style="margin-left: 20px;">Third order line quantity 3 is between 1 to 5 in Product Rule Line.</p> <p style="margin-left: 20px;">Third order line quantity 3 is between 1 to 5 in Product Rule Line.</p>
<p style="margin-left: 20px;">Unit Price(25) is less than Fixed Amount(50) of Product Rule Lines.</p> <p style="margin-left: 20px;">Unit Price(25) is less than Fixed Amount(50) of Product Rule Lines.</p>
<p style="margin-left: 20px;">so, it give <b> 100% </b> discount for that line.</p> <p style="margin-left: 20px;">so, it gives <b> 100% </b> discount for that line.</p>
</p> </p>
</div> </div>
</div> </div>
@ -191,12 +191,12 @@
<div class="row oe_spaced"> <div class="row oe_spaced">
<div class="oe_demo oe_picture oe_screenshot"> <div class="oe_demo oe_picture oe_screenshot">
<p class="text-justify"> <p class="text-justify">
<h4>First order line discount caculation:</h4> </br> <h4>First order line discount calculation:</h4> </br>
<p style="margin-left: 20px;"><b>Product Lines Rules:</b></p> <p style="margin-left: 20px;"><b>Product Lines Rules:</b></p>
<p style="margin-left: 20px;">4.9 % of Match first Product Rule Lines beacuse ordered Qty 5 is between 1 to 6.</p> <p style="margin-left: 20px;">4.9 % of Match first Product Rule Lines because ordered Qty 5 is between 1 to 6.</p>
<p style="margin-left: 20px;"><b>Cart Rules:</b></p> <p style="margin-left: 20px;"><b>Cart Rules:</b></p>
<p style="margin-left: 20px;">First cart Rules not match beacuse Subtotal is greater than : 3,000.00 so that rules skip.</p> <p style="margin-left: 20px;">First cart Rules do not match because Subtotal is greater than 3,000.00 so that rules skip.</p>
<p style="margin-left: 20px;">Second Cart Rules match beacuse Sum of Item Qty at least : 7.00 (here 8 = 5 + 3 ). so add 10 %.</p> <p style="margin-left: 20px;">Second Cart Rules match because Sum of Item Qty At Least: 7.00 (here 8 = 5 + 3 ). so add 10 %.</p>
<p style="margin-left: 20px;"><b>Coupon Code: Coupon code get 10 percent free.</b> <p style="margin-left: 20px;"><b>Coupon Code: Coupon code get 10 percent free.</b>
<p style="margin-left: 20px;">Discount Formula= <b> Product Rule line + Cart Rules + Coupon Code</b></p> <p style="margin-left: 20px;">Discount Formula= <b> Product Rule line + Cart Rules + Coupon Code</b></p>
<p style="margin-left: 20px;">First line discount is 24.9 %( 4.9 + 10 + 10)</p> <p style="margin-left: 20px;">First line discount is 24.9 %( 4.9 + 10 + 10)</p>

View File

@ -112,10 +112,9 @@ class TestMixAllDiscount(TestAdvSalePricelist):
first_order_line = self.sale_order.order_line[0] first_order_line = self.sale_order.order_line[0]
first_order_line._onchange_discount() first_order_line._onchange_discount()
self.assertEqual(first_order_line.discount, 12.5, self.assertEqual(first_order_line.discount, 19.0,
'Discount Percentage: the discount for the' 'Discount Percentage: the discount for the'
' sale order line should be 12.5!') ' sale order line should be 19.0!')
self.sale_order._check_cart_rules()
# Set coupon code with percent # Set coupon code with percent
self.check_all_condition(self.sale_order, 'percent') self.check_all_condition(self.sale_order, 'percent')
@ -142,11 +141,6 @@ class TestMixAllDiscount(TestAdvSalePricelist):
first_order_line = self.sale_order_1.order_line[0] first_order_line = self.sale_order_1.order_line[0]
first_order_line._onchange_discount() first_order_line._onchange_discount()
self.assertEqual(first_order_line.discount, 15.00,
'Discount Percentage: the discount for the'
' first sale order line should be 15!')
self.sale_order_1._check_cart_rules()
self.assertEqual(first_order_line.discount, 21.50, self.assertEqual(first_order_line.discount, 21.50,
'Discount Percentage: the discount for the' 'Discount Percentage: the discount for the'
' first sale order line should be 21.50!') ' first sale order line should be 21.50!')
@ -162,11 +156,7 @@ class TestMixAllDiscount(TestAdvSalePricelist):
self.coupon_code_id.write({'coupon_type': coupon_type, self.coupon_code_id.write({'coupon_type': coupon_type,
'apply_on': 'category', 'apply_on': 'category',
'categ_id': self.category_id.id, 'categ_id': self.category_id.id})
'discount_amount': 0.0,
'number_of_y_product': 0.0,
'number_of_y_product': 0.0,
'other_product_id': False})
if coupon_type in ['percent', 'fixed_amount']: if coupon_type in ['percent', 'fixed_amount']:
self.coupon_code_id.write({'discount_amount': 20}) self.coupon_code_id.write({'discount_amount': 20})
elif coupon_type == 'buy_x_get_percent': elif coupon_type == 'buy_x_get_percent':
@ -181,6 +171,7 @@ class TestMixAllDiscount(TestAdvSalePricelist):
'number_of_y_product': 1, 'number_of_y_product': 1,
'discount_amount': 0.0, 'discount_amount': 0.0,
'other_product_id': self.product_3.id}) 'other_product_id': self.product_3.id})
self.coupon_code_id.check_percentage()
# Category Coupon Code # Category Coupon Code
self.check_all_coupon_code(sale_order, self.check_all_coupon_code(sale_order,
'GetDiscount', self.pricelist_id) 'GetDiscount', self.pricelist_id)

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<flectra> <flectra>
<record id="product_pricelist_view_flectra" model="ir.ui.view"> <record id="product_pricelist_view_advance" model="ir.ui.view">
<field name="name">product.pricelist.flectra.form</field> <field name="name">product.pricelist.advance.form</field>
<field name="model">product.pricelist</field> <field name="model">product.pricelist</field>
<field name="inherit_id" ref="product.product_pricelist_view"/> <field name="inherit_id" ref="product.product_pricelist_view"/>
<field name="arch" type="xml"> <field name="arch" type="xml">

View File

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<flectra> <flectra>
<record id="view_order_form_flectra" model="ir.ui.view"> <record id="view_order_form_advance" model="ir.ui.view">
<field name="name">sale.order.flectra.form</field> <field name="name">sale.order.advance.form</field>
<field name="model">sale.order</field> <field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/> <field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml"> <field name="arch" type="xml">

View File

@ -21,7 +21,8 @@ class SaleOrder(models.Model):
record.discount = record.pricelist_id.currency_id.round(total_discount) record.discount = record.pricelist_id.currency_id.round(total_discount)
@api.multi @api.multi
@api.depends('order_line', 'discount_per', 'discount_amount') @api.depends('order_line', 'discount_per', 'discount_amount',
'order_line.product_uom_qty', 'order_line.price_unit')
def _get_total_amount(self): def _get_total_amount(self):
for order_id in self: for order_id in self:
order_id.gross_amount = sum( order_id.gross_amount = sum(