summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristophe Simonis <chs@odoo.com>2016-11-18 16:46:53 +0100
committerChristophe Simonis <chs@odoo.com>2016-11-18 16:46:53 +0100
commit4e7eda8b85a862849f4e03fe5cefa83e44ac258a (patch)
tree623125decb91fe321a03d14b8e7117a759069663
parent3b2f4e244f51b37050f61629bf01e6dc38cc4817 (diff)
parent95abb2224d3541bf37f77717f81eee290d9fcd4f (diff)
[MERGE] forward port branch 9.0 up to 95abb22
-rw-r--r--addons/payment_paypal/controllers/main.py37
-rw-r--r--addons/sale/sale.py4
-rw-r--r--addons/sale_margin/models/sale_order.py12
-rw-r--r--addons/website_livechat/views/website_livechat.xml2
-rw-r--r--addons/website_quote/models/order.py5
-rw-r--r--openerp/addons/base/res/res_bank.py2
6 files changed, 52 insertions, 10 deletions
diff --git a/addons/payment_paypal/controllers/main.py b/addons/payment_paypal/controllers/main.py
index f840a33d6eb..e71ef8d2546 100644
--- a/addons/payment_paypal/controllers/main.py
+++ b/addons/payment_paypal/controllers/main.py
@@ -21,18 +21,33 @@ class PaypalController(http.Controller):
""" Extract the return URL from the data coming from paypal. """
return_url = post.pop('return_url', '')
if not return_url:
- custom = json.loads(post.pop('custom', False) or '{}')
+ custom = json.loads(post.pop('custom', False) or post.pop('cm', False) or '{}')
return_url = custom.get('return_url', '/')
return return_url
+ def _parse_pdt_response(self, response):
+ """ Parse a text reponse for a PDT verification .
+
+ :param response str: text response, structured in the following way:
+ STATUS\nkey1=value1\nkey2=value2...\n
+ :rtype tuple(str, dict)
+ :return: tuple containing the STATUS str and the key/value pairs
+ parsed as a dict
+ """
+ lines = filter(None, response.split('\n'))
+ status = lines.pop(0)
+ pdt_post = dict(line.split('=', 1) for line in lines)
+ return status, pdt_post
+
def paypal_validate_data(self, **post):
""" Paypal IPN: three steps validation to ensure data correctness
- step 1: return an empty HTTP 200 response -> will be done at the end
by returning ''
- step 2: POST the complete, unaltered message back to Paypal (preceded
- by cmd=_notify-validate), with same encoding
- - step 3: paypal send either VERIFIED or INVALID (single word)
+ by cmd=_notify-validate or _notify-synch for PDT), with same encoding
+ - step 3: paypal send either VERIFIED or INVALID (single word) for IPN
+ or SUCCESS or FAIL (+ data) for PDT
Once data is validated, process it. """
res = False
@@ -44,18 +59,26 @@ class PaypalController(http.Controller):
tx_ids = request.registry['payment.transaction'].search(cr, uid, [('reference', '=', reference)], context=context)
if tx_ids:
tx = request.registry['payment.transaction'].browse(cr, uid, tx_ids[0], context=context)
+ pdt_request = bool(new_post.get('amt')) # check for spefific pdt param
+ if pdt_request:
+ # this means we are in PDT instead of DPN like before
+ # fetch the PDT token
+ new_post['at'] = request.registry['ir.config_parameter'].get_param(cr, SUPERUSER_ID, 'payment_paypal.pdt_token')
+ new_post['cmd'] = '_notify-synch' # command is different in PDT than IPN/DPN
paypal_urls = request.registry['payment.acquirer']._get_paypal_urls(cr, uid, tx and tx.acquirer_id and tx.acquirer_id.environment or 'prod', context=context)
validate_url = paypal_urls['paypal_form_url']
urequest = urllib2.Request(validate_url, werkzeug.url_encode(new_post))
uopen = urllib2.urlopen(urequest)
resp = uopen.read()
- if resp == 'VERIFIED':
+ if pdt_request:
+ resp, post = self._parse_pdt_response(resp)
+ if resp == 'VERIFIED' or pdt_request and resp == 'SUCCESS':
_logger.info('Paypal: validated data')
res = request.registry['payment.transaction'].form_feedback(cr, SUPERUSER_ID, post, 'paypal', context=context)
- elif resp == 'INVALID':
- _logger.warning('Paypal: answered INVALID on data verification')
+ elif resp == 'INVALID' or pdt_request and resp == 'FAIL':
+ _logger.warning('Paypal: answered INVALID/FAIL on data verification')
else:
- _logger.warning('Paypal: unrecognized paypal answer, received %s instead of VERIFIED or INVALID' % resp.text)
+ _logger.warning('Paypal: unrecognized paypal answer, received %s instead of VERIFIED/SUCCESS or INVALID/FAIL (validation: %s)' % (resp, 'PDT' if pdt_request else 'IPN/DPN'))
return res
@http.route('/payment/paypal/ipn/', type='http', auth='none', methods=['POST'], csrf=False)
diff --git a/addons/sale/sale.py b/addons/sale/sale.py
index e6f660dbaf5..b05ef447b42 100644
--- a/addons/sale/sale.py
+++ b/addons/sale/sale.py
@@ -660,6 +660,10 @@ class SaleOrderLine(models.Model):
return []
@api.model
+ def _get_purchase_price(self, pricelist, product, product_uom, date):
+ return {}
+
+ @api.model
def create(self, values):
onchange_fields = ['name', 'price_unit', 'product_uom', 'tax_id']
if values.get('order_id') and values.get('product_id') and any(f not in values for f in onchange_fields):
diff --git a/addons/sale_margin/models/sale_order.py b/addons/sale_margin/models/sale_order.py
index a8e1ed6ef8b..d546882e143 100644
--- a/addons/sale_margin/models/sale_order.py
+++ b/addons/sale_margin/models/sale_order.py
@@ -22,6 +22,18 @@ class SaleOrderLine(models.Model):
price = frm_cur.with_context(ctx).compute(purchase_price, to_cur, round=False)
return price
+ @api.model
+ def _get_purchase_price(self, pricelist, product, product_uom, date):
+ frm_cur = self.env.user.company_id.currency_id
+ to_cur = pricelist.currency_id
+ purchase_price = product.standard_price
+ if product_uom != product.uom_id:
+ purchase_price = self.env['product.uom']._compute_price(product.uom_id.id, purchase_price, to_uom_id=product_uom.id)
+ ctx = self.env.context.copy()
+ ctx['date'] = date
+ price = frm_cur.with_context(ctx).compute(purchase_price, to_cur, round=False)
+ return {'purchase_price': price}
+
@api.onchange('product_id', 'product_uom')
def product_id_change_margin(self):
if not self.order_id.pricelist_id or not self.product_id or not self.product_uom:
diff --git a/addons/website_livechat/views/website_livechat.xml b/addons/website_livechat/views/website_livechat.xml
index fe1b71550c2..f1c5d643f6a 100644
--- a/addons/website_livechat/views/website_livechat.xml
+++ b/addons/website_livechat/views/website_livechat.xml
@@ -124,7 +124,7 @@
<h3>The Team</h3>
<t t-foreach="team" t-as="user" class="media">
<div class="media">
- <div class="pull-left">
+ <div class="pull-left" t-if='user.image_small'>
<img t-att-src="'data:image/png;base64,' + user.image_small" class="img-rounded" t-att-alt="user.name"/>
</div>
<div class="media-body">
diff --git a/addons/website_quote/models/order.py b/addons/website_quote/models/order.py
index f236ea24541..d602e57345a 100644
--- a/addons/website_quote/models/order.py
+++ b/addons/website_quote/models/order.py
@@ -203,12 +203,15 @@ class sale_order(osv.osv):
lines = [(5,)]
quote_template = self.pool.get('sale.quote.template').browse(cr, uid, template_id, context=context)
for line in quote_template.quote_line:
+ date = time.strftime('%Y-%m-%d')
res = self.pool.get('sale.order.line').product_id_change(cr, uid, False,
False, line.product_id.id, line.product_uom_qty, line.product_uom_id.id, line.product_uom_qty,
- line.product_uom_id.id, line.name, partner, False, True, time.strftime('%Y-%m-%d'),
+ line.product_uom_id.id, line.name, partner, False, True, date,
False, fiscal_position_id, True, context)
data = res.get('value', {})
if pricelist_id:
+ pricelist = self.pool['product.pricelist'].browse(cr, uid, [pricelist_id], context=context)[0]
+ data.update(self.pool['sale.order.line']._get_purchase_price(cr, uid, pricelist, line.product_id, line.product_uom_id, date, context=context))
uom_context = context.copy()
uom_context['uom'] = line.product_uom_id.id
price = pricelist_obj.price_get(cr, uid, [pricelist_id], line.product_id.id, 1, context=uom_context)[pricelist_id]
diff --git a/openerp/addons/base/res/res_bank.py b/openerp/addons/base/res/res_bank.py
index 3b84684f94e..0666e853564 100644
--- a/openerp/addons/base/res/res_bank.py
+++ b/openerp/addons/base/res/res_bank.py
@@ -69,7 +69,7 @@ class ResPartnerBank(models.Model):
company_id = fields.Many2one('res.company', 'Company', default=lambda self: self.env.user.company_id, ondelete='cascade')
_sql_constraints = [
- ('unique_number', 'unique(sanitized_acc_number)', 'Account Number must be unique'),
+ ('unique_number', 'unique(sanitized_acc_number, company_id)', 'Account Number must be unique'),
]
@api.depends('acc_number')