[FIX] account_facturx: Fix partner detection / price_unit

- price_unit is wrong because Facturx only provide the price_total and then,
we need to divide this amount by the quantity.

- the partner detection using its name was buggy due to the 'elements' variable
that was overrided.

-opw: 1938648

closes odoo/odoo#30998
This commit is contained in:
Laurent Smet
2019-02-11 14:02:10 +00:00
parent 3915c2d236
commit f8379352df
@@ -64,12 +64,11 @@ class AccountInvoice(models.Model):
with Form(self_ctx, view='account.invoice_supplier_form') as invoice_form:
# Partner (first step to avoid warning 'Warning! You must first select a partner.').
elements = tree.xpath('//ram:SellerTradeParty/ram:Name', namespaces=tree.nsmap)
partner_name = elements and elements[0].text
elements = tree.xpath('//ram:SellerTradeParty/ram:SpecifiedTaxRegistration/ram:ID', namespaces=tree.nsmap)
partner = elements and self.env['res.partner'].search([('vat', '=', elements[0].text)], limit=1)
if not partner:
elements = tree.xpath('//ram:SellerTradeParty/ram:Name', namespaces=tree.nsmap)
partner_name = elements and elements[0].text
partner = elements and self.env['res.partner'].search([('name', 'ilike', partner_name)], limit=1)
if not partner:
elements = tree.xpath('//ram:SellerTradeParty//ram:URIID[@schemeID=\'SMTP\']', namespaces=tree.nsmap)
@@ -161,20 +160,20 @@ class AccountInvoice(models.Model):
if product:
invoice_line_form.product_id = product
# Price Unit.
line_elements = element.xpath('.//ram:GrossPriceProductTradePrice/ram:ChargeAmount', namespaces=tree.nsmap)
if line_elements:
invoice_line_form.price_unit = float(line_elements[0].text)
else:
line_elements = element.xpath('.//ram:NetPriceProductTradePrice/ram:ChargeAmount', namespaces=tree.nsmap)
if line_elements:
invoice_line_form.price_unit = float(line_elements[0].text)
# Quantity.
line_elements = element.xpath('.//ram:SpecifiedLineTradeDelivery/ram:BilledQuantity', namespaces=tree.nsmap)
if line_elements:
invoice_line_form.quantity = float(line_elements[0].text) * refund_sign
# Price Unit.
line_elements = element.xpath('.//ram:GrossPriceProductTradePrice/ram:ChargeAmount', namespaces=tree.nsmap)
if line_elements:
invoice_line_form.price_unit = float(line_elements[0].text) / invoice_line_form.quantity
else:
line_elements = element.xpath('.//ram:NetPriceProductTradePrice/ram:ChargeAmount', namespaces=tree.nsmap)
if line_elements:
invoice_line_form.price_unit = float(line_elements[0].text) / invoice_line_form.quantity
# Discount.
line_elements = element.xpath('.//ram:AppliedTradeAllowanceCharge/ram:CalculationPercent', namespaces=tree.nsmap)
if line_elements: