diff --git a/addons/account/wizard/wizard_tax_adjustments.py b/addons/account/wizard/wizard_tax_adjustments.py index 8c5002347c0..22d2235ef04 100644 --- a/addons/account/wizard/wizard_tax_adjustments.py +++ b/addons/account/wizard/wizard_tax_adjustments.py @@ -18,24 +18,26 @@ class TaxAdjustments(models.TransientModel): debit_account_id = fields.Many2one('account.account', string='Debit account', required=True, domain=[('deprecated', '=', False)]) credit_account_id = fields.Many2one('account.account', string='Credit account', required=True, domain=[('deprecated', '=', False)]) amount = fields.Monetary(currency_field='company_currency_id', required=True) + adjustment_type = fields.Selection([('debit', 'Adjustment in favor of the Estate'), ('credit', 'Adjustment in your favor')], string="Adjustment Type", store=False, required=True) company_currency_id = fields.Many2one('res.currency', readonly=True, default=lambda self: self.env.user.company_id.currency_id) tax_id = fields.Many2one('account.tax', string='Adjustment Tax', ondelete='restrict', domain=[('type_tax_use', '=', 'none'), ('tax_adjustment', '=', True)], required=True) @api.multi def _create_move(self): + adjustment_type = self.env.context.get('adjustment_type', (self.amount > 0.0 and 'debit' or 'credit')) debit_vals = { 'name': self.reason, - 'debit': self.amount, + 'debit': abs(self.amount), 'credit': 0.0, 'account_id': self.debit_account_id.id, - 'tax_line_id': self.tax_id.id, + 'tax_line_id': adjustment_type == 'debit' and self.tax_id.id or False, } credit_vals = { 'name': self.reason, 'debit': 0.0, - 'credit': self.amount, + 'credit': abs(self.amount), 'account_id': self.credit_account_id.id, - 'tax_line_id': self.tax_id.id, + 'tax_line_id': adjustment_type == 'credit' and self.tax_id.id or False, } vals = { 'journal_id': self.journal_id.id, @@ -48,6 +50,13 @@ class TaxAdjustments(models.TransientModel): return move.id @api.multi + def create_move_debit(self): + return self.with_context(adjustment_type='debit').create_move() + + @api.multi + def create_move_credit(self): + return self.with_context(adjustment_type='credit').create_move() + def create_move(self): #create the adjustment move move_id = self._create_move() diff --git a/addons/account/wizard/wizard_tax_adjustments_view.xml b/addons/account/wizard/wizard_tax_adjustments_view.xml index 3d4ed0a9e9a..dba164388b9 100644 --- a/addons/account/wizard/wizard_tax_adjustments_view.xml +++ b/addons/account/wizard/wizard_tax_adjustments_view.xml @@ -12,6 +12,7 @@ + @@ -26,8 +27,14 @@ diff --git a/addons/account_asset/models/account_asset.py b/addons/account_asset/models/account_asset.py index 8d4119659f1..75d5467a94d 100644 --- a/addons/account_asset/models/account_asset.py +++ b/addons/account_asset/models/account_asset.py @@ -416,7 +416,7 @@ class AccountAssetAsset(models.Model): @api.model def create(self, vals): asset = super(AccountAssetAsset, self.with_context(mail_create_nolog=True)).create(vals) - asset.compute_depreciation_board() + asset.sudo().compute_depreciation_board() return asset @api.multi diff --git a/addons/hr_timesheet/report/report_timesheet_templates.xml b/addons/hr_timesheet/report/report_timesheet_templates.xml index e6d0f0905cf..fea714a5d7a 100644 --- a/addons/hr_timesheet/report/report_timesheet_templates.xml +++ b/addons/hr_timesheet/report/report_timesheet_templates.xml @@ -36,7 +36,7 @@ - + @@ -72,4 +72,4 @@ name="hr_timesheet.report_timesheet" file="report_timesheet" /> - \ No newline at end of file + diff --git a/addons/http_routing/geoipresolver.py b/addons/http_routing/geoipresolver.py new file mode 100644 index 00000000000..1f9b0e22724 --- /dev/null +++ b/addons/http_routing/geoipresolver.py @@ -0,0 +1,60 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +import os.path + +try: + import GeoIP # Legacy +except ImportError: + GeoIP = None + +try: + import geoip2 + import geoip2.database +except ImportError: + geoip2 = None + +class GeoIPResolver(object): + def __init__(self, fname): + self.fname = fname + try: + self._db = geoip2.database.Reader(fname) + self.version = 2 + except Exception: + try: + self._db = GeoIP.open(fname, GeoIP.GEOIP_STANDARD) + self.version = 1 + assert self._db.database_info is not None + except Exception: + raise ValueError('Invalid GeoIP database: %r' % fname) + + def __del__(self): + if self.version == 2: + self._db.close() + + @classmethod + def open(cls, fname): + if not GeoIP and not geoip2: + return None + if not os.path.exists(fname): + return None + return GeoIPResolver(fname) + + def resolve(self, ip): + if self.version == 1: + return self._db.record_by_addr(ip) or {} + elif self.version == 2: + try: + r = self._db.city(ip) + except (ValueError, geoip2.errors.AddressNotFoundError): + return {} + return { + 'city': r.city.name, + 'country_code': r.country.iso_code, + 'country_name': r.country.name, + 'region': r.subdivisions[0].iso_code if r.subdivisions else None, + 'time_zone': r.location.time_zone, + } + + # compat + def record_by_addr(self, addr): + return self.resolve(addr) diff --git a/addons/http_routing/models/ir_http.py b/addons/http_routing/models/ir_http.py index 344b3b52567..0129bc90e6d 100644 --- a/addons/http_routing/models/ir_http.py +++ b/addons/http_routing/models/ir_http.py @@ -18,6 +18,8 @@ from odoo.addons.base.ir.ir_http import RequestUID, ModelConverter from odoo.http import request from odoo.tools import config, ustr, pycompat +from ..geoipresolver import GeoIPResolver + _logger = logging.getLogger(__name__) # global resolver (GeoIP API is thread-safe, for multithreaded workers) @@ -265,25 +267,18 @@ class IrHttp(models.AbstractModel): # Lazy init of GeoIP resolver if odoo._geoip_resolver is not None: return + geofile = config.get('geoip_database') try: - import GeoIP - # updated database can be downloaded on MaxMind website - # http://dev.maxmind.com/geoip/legacy/install/city/ - geofile = config.get('geoip_database') - if os.path.exists(geofile): - odoo._geoip_resolver = GeoIP.open(geofile, GeoIP.GEOIP_STANDARD) - else: - odoo._geoip_resolver = False - _logger.warning('GeoIP database file %r does not exists, apt-get install geoip-database-contrib or download it from http://dev.maxmind.com/geoip/legacy/install/city/', geofile) - except ImportError: - odoo._geoip_resolver = False + odoo._geoip_resolver = GeoIPResolver.open(geofile) or False + except Exception as e: + _logger.warning('Cannot load GeoIP: %s', ustr(e)) @classmethod def _geoip_resolve(cls): if 'geoip' not in request.session: record = {} if odoo._geoip_resolver and request.httprequest.remote_addr: - record = odoo._geoip_resolver.record_by_addr(request.httprequest.remote_addr) or {} + record = odoo._geoip_resolver.resolve(request.httprequest.remote_addr) or {} request.session['geoip'] = record @classmethod diff --git a/addons/payment_stripe/models/payment.py b/addons/payment_stripe/models/payment.py index 2d3cec0c312..1adebf763b6 100644 --- a/addons/payment_stripe/models/payment.py +++ b/addons/payment_stripe/models/payment.py @@ -126,7 +126,7 @@ class PaymentTransactionStripe(models.Model): @api.multi def stripe_s2s_do_transaction(self, **kwargs): self.ensure_one() - result = self._create_stripe_charge(acquirer_ref=self.payment_token_id.acquirer_ref) + result = self._create_stripe_charge(acquirer_ref=self.payment_token_id.acquirer_ref, email=self.partner_email) return self._stripe_s2s_validate_tree(result) diff --git a/addons/point_of_sale/static/src/js/models.js b/addons/point_of_sale/static/src/js/models.js index fb6e271a7d1..24443942ba5 100644 --- a/addons/point_of_sale/static/src/js/models.js +++ b/addons/point_of_sale/static/src/js/models.js @@ -1385,7 +1385,8 @@ exports.Orderline = Backbone.Model.extend({ if (unit.rounding) { this.quantity = round_pr(quant, unit.rounding); var decimals = this.pos.dp['Product Unit of Measure']; - this.quantityStr = field_utils.format.float(round_di(this.quantity, decimals), {digits: [69, decimals]}); + this.quantity = round_di(this.quantity, decimals) + this.quantityStr = field_utils.format.float(this.quantity, {digits: [69, decimals]}); } else { this.quantity = round_pr(quant, 1); this.quantityStr = this.quantity.toFixed(0); diff --git a/addons/pos_mercury/data/pos_mercury_demo.xml b/addons/pos_mercury/data/pos_mercury_demo.xml index 5ff1a0d70e4..b242868f8df 100644 --- a/addons/pos_mercury/data/pos_mercury_demo.xml +++ b/addons/pos_mercury/data/pos_mercury_demo.xml @@ -5,8 +5,8 @@ Mercury Demo - 334160 - 81303DUR + 755847002 + xyz diff --git a/addons/pos_mercury/models/pos_mercury.py b/addons/pos_mercury/models/pos_mercury.py index 0a329634e5e..0c48502ee76 100644 --- a/addons/pos_mercury/models/pos_mercury.py +++ b/addons/pos_mercury/models/pos_mercury.py @@ -4,6 +4,7 @@ import logging from odoo import models, fields, api, _ +from odoo.tools.float_utils import float_compare _logger = logging.getLogger(__name__) @@ -71,8 +72,9 @@ class PosOrder(models.Model): statement_id = super(PosOrder, self).add_payment(data) statement_lines = self.env['account.bank.statement.line'].search([('statement_id', '=', statement_id), ('pos_statement_id', '=', self.id), - ('journal_id', '=', data['journal']), - ('amount', '=', data['amount'])]) + ('journal_id', '=', data['journal'])]) + statement_lines = statement_lines.filtered(lambda line: float_compare(line.amount, data['amount'], + precision_rounding=line.journal_currency_id.rounding) == 0) # we can get multiple statement_lines when there are >1 credit # card payments with the same amount. In that case it doesn't diff --git a/addons/pos_mercury/models/pos_mercury_transaction.py b/addons/pos_mercury/models/pos_mercury_transaction.py index ade1f15c729..72faef7f207 100644 --- a/addons/pos_mercury/models/pos_mercury_transaction.py +++ b/addons/pos_mercury/models/pos_mercury_transaction.py @@ -61,11 +61,15 @@ class MercuryTransaction(models.Model): 'SOAPAction': 'http://www.mercurypay.com/CreditTransaction', } + url = 'https://w1.mercurypay.com/ws/ws.asmx' + if self.env['ir.config_parameter'].sudo().get_param('pos_mercury.enable_test_env'): + url = 'https://w1.mercurycert.net/ws/ws.asmx' + try: - r = requests.post('https://w1.mercurypay.com/ws/ws.asmx', data=xml_transaction, headers=headers, timeout=65) + r = requests.post(url, data=xml_transaction, headers=headers, timeout=65) r.raise_for_status() response = werkzeug.utils.unescape(r.content.decode()) - except: + except Exception: response = "timeout" return response diff --git a/addons/sale/models/account_invoice.py b/addons/sale/models/account_invoice.py index a03df305b16..0a2406a0968 100644 --- a/addons/sale/models/account_invoice.py +++ b/addons/sale/models/account_invoice.py @@ -39,6 +39,9 @@ class AccountInvoice(models.Model): def _onchange_delivery_address(self): addr = self.partner_id.address_get(['delivery']) self.partner_shipping_id = addr and addr.get('delivery') + if self.env.context.get('type', 'out_invoice') == 'out_invoice': + company = self.company_id or self.env.user.company_id + self.comment = company.with_context(lang=self.partner_id.lang).sale_note @api.multi def action_invoice_paid(self): diff --git a/addons/sale/wizard/sale_make_invoice_advance.py b/addons/sale/wizard/sale_make_invoice_advance.py index 089a898f67a..97ef9c726f9 100644 --- a/addons/sale/wizard/sale_make_invoice_advance.py +++ b/addons/sale/wizard/sale_make_invoice_advance.py @@ -65,7 +65,7 @@ class SaleAdvancePaymentInv(models.TransientModel): account_id = False if self.product_id.id: - account_id = self.product_id.property_account_income_id.id + account_id = self.product_id.property_account_income_id.id or self.product_id.categ_id.property_account_income_categ_id.id if not account_id: inc_acc = ir_property_obj.get('property_account_income_categ_id', 'product.category') account_id = order.fiscal_position_id.map_account(inc_acc).id if inc_acc else False diff --git a/addons/stock/report/report_location_barcode.xml b/addons/stock/report/report_location_barcode.xml index 93aee57f27b..426f7037e28 100644 --- a/addons/stock/report/report_location_barcode.xml +++ b/addons/stock/report/report_location_barcode.xml @@ -9,8 +9,8 @@