[MERGE] forward port branch saas-11 up to 4e7eda8

This commit is contained in:
Christophe Simonis
2016-11-18 16:50:20 +01:00
6 changed files with 52 additions and 10 deletions
+30 -7
View File
@@ -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)
+4
View File
@@ -688,6 +688,10 @@ class SaleOrderLine(models.Model):
new_procs.run()
return new_procs
@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']
+12
View File
@@ -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:
@@ -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">
+4 -1
View File
@@ -205,12 +205,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]
+1 -1
View File
@@ -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')