read_listdata() --> classmethod
This commit is contained in:
parent
cf98fdf2ad
commit
530f37a06b
1 changed files with 72 additions and 59 deletions
75
document.py
75
document.py
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
import os.path
|
import os.path
|
||||||
import json
|
import json
|
||||||
|
import copy
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
from datetime import datetime, date
|
from datetime import datetime, date
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
|
@ -633,6 +634,8 @@ class Incoming(metaclass=PoolMeta):
|
||||||
line.account = expense_accounts[0]
|
line.account = expense_accounts[0]
|
||||||
|
|
||||||
# check if calculated 'amount' matches with amount from xml-data
|
# check if calculated 'amount' matches with amount from xml-data
|
||||||
|
assert invoice.currency is not None
|
||||||
|
|
||||||
xml_amount = line_data.get('total', {}).pop('amount', None)
|
xml_amount = line_data.get('total', {}).pop('amount', None)
|
||||||
if xml_amount is not None:
|
if xml_amount is not None:
|
||||||
if xml_amount != line.get_amount(None):
|
if xml_amount != line.get_amount(None):
|
||||||
|
@ -667,25 +670,16 @@ class Incoming(metaclass=PoolMeta):
|
||||||
'document_incoming_invoice_xml.msg_unused_linevalues'),
|
'document_incoming_invoice_xml.msg_unused_linevalues'),
|
||||||
json.dumps(line_data, cls=JSONEncoder, indent=3)])
|
json.dumps(line_data, cls=JSONEncoder, indent=3)])
|
||||||
line.note = '\n'.join(x for x in notes if x)
|
line.note = '\n'.join(x for x in notes if x)
|
||||||
|
|
||||||
line.on_change_invoice()
|
line.on_change_invoice()
|
||||||
return line
|
return line
|
||||||
|
|
||||||
def _readxml_invoice_line(self, xmldata, xpth, pos):
|
def _readxml_read_listdata(self, xmldata, xpth, xtag, key_list):
|
||||||
""" read invoice-line from xml
|
|
||||||
|
|
||||||
Args:
|
|
||||||
xmldata (): xml-tree object
|
|
||||||
xpth (list): xpath to invoice-line
|
|
||||||
pos (int): number of line to read
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
dict: invoice line data
|
|
||||||
"""
|
|
||||||
def read_listdata(xtag, key_list):
|
|
||||||
""" read list of values from xml
|
""" read list of values from xml
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
|
xmldata (xtree): xml-tree
|
||||||
|
xpth (list): list of xml-tags until index-counter
|
||||||
|
pos (int): position in list
|
||||||
xtag (str): xml-tag to read as list
|
xtag (str): xml-tag to read as list
|
||||||
key_list (list): [('<xtag>', '<key>')]
|
key_list (list): [('<xtag>', '<key>')]
|
||||||
|
|
||||||
|
@ -694,7 +688,7 @@ class Incoming(metaclass=PoolMeta):
|
||||||
"""
|
"""
|
||||||
if isinstance(xtag, str):
|
if isinstance(xtag, str):
|
||||||
xtag = [xtag]
|
xtag = [xtag]
|
||||||
xpath_list = xpth + [pos] + xtag
|
xpath_list = xpth + xtag
|
||||||
num_listitem = len(xmldata.xpath(
|
num_listitem = len(xmldata.xpath(
|
||||||
self._readxml_xpath(xpath_list), namespaces=xmldata.nsmap))
|
self._readxml_xpath(xpath_list), namespaces=xmldata.nsmap))
|
||||||
listdata = []
|
listdata = []
|
||||||
|
@ -713,12 +707,24 @@ class Incoming(metaclass=PoolMeta):
|
||||||
listdata.append(values)
|
listdata.append(values)
|
||||||
return listdata
|
return listdata
|
||||||
|
|
||||||
|
def _readxml_invoice_line(self, xmldata, xpth, pos):
|
||||||
|
""" read invoice-line from xml
|
||||||
|
|
||||||
|
Args:
|
||||||
|
xmldata (): xml-tree object
|
||||||
|
xpth (list): xpath to invoice-line
|
||||||
|
pos (int): number of line to read
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
dict: invoice line data
|
||||||
|
"""
|
||||||
|
xpath_line = xpth + [pos]
|
||||||
result = {'convert_note': []}
|
result = {'convert_note': []}
|
||||||
result['line_no'] = self._readxml_getvalue(xmldata, xpth + [pos] + [
|
result['line_no'] = self._readxml_getvalue(xmldata, xpath_line + [
|
||||||
'ram:AssociatedDocumentLineDocument', 'ram:LineID'])
|
'ram:AssociatedDocumentLineDocument', 'ram:LineID'])
|
||||||
|
|
||||||
result['line_note'] = '\n'.join(self._readxml_getvalue(
|
result['line_note'] = '\n'.join(self._readxml_getvalue(
|
||||||
xmldata, xpth + [pos] + [
|
xmldata, xpath_line + [
|
||||||
'ram:AssociatedDocumentLineDocument', 'ram:IncludedNote',
|
'ram:AssociatedDocumentLineDocument', 'ram:IncludedNote',
|
||||||
'ram:Content'], allow_list=True))
|
'ram:Content'], allow_list=True))
|
||||||
|
|
||||||
|
@ -736,11 +742,12 @@ class Incoming(metaclass=PoolMeta):
|
||||||
('ram:ModelName', 'model_name'),
|
('ram:ModelName', 'model_name'),
|
||||||
('ram:OriginTradeCountry', 'trade_country')
|
('ram:OriginTradeCountry', 'trade_country')
|
||||||
]:
|
]:
|
||||||
result[key] = self._readxml_getvalue(xmldata, xpth + [pos] + [
|
result[key] = self._readxml_getvalue(xmldata, xpath_line + [
|
||||||
'ram:SpecifiedTradeProduct', xkey])
|
'ram:SpecifiedTradeProduct', xkey])
|
||||||
|
|
||||||
# attributes of product
|
# attributes of product
|
||||||
result['attributes'] = read_listdata([
|
result['attributes'] = self._readxml_read_listdata(
|
||||||
|
xmldata, xpath_line, [
|
||||||
'ram:SpecifiedTradeProduct',
|
'ram:SpecifiedTradeProduct',
|
||||||
'ram:ApplicableProductCharacteristic'], [
|
'ram:ApplicableProductCharacteristic'], [
|
||||||
('ram:TypeCode', 'code'),
|
('ram:TypeCode', 'code'),
|
||||||
|
@ -749,21 +756,24 @@ class Incoming(metaclass=PoolMeta):
|
||||||
('ram:ValueY', 'value')])
|
('ram:ValueY', 'value')])
|
||||||
|
|
||||||
# classification of product
|
# classification of product
|
||||||
result['classification'] = read_listdata([
|
result['classification'] = self._readxml_read_listdata(
|
||||||
|
xmldata, xpath_line, [
|
||||||
'ram:SpecifiedTradeProduct',
|
'ram:SpecifiedTradeProduct',
|
||||||
'ram:DesignatedProductClassification'], [
|
'ram:DesignatedProductClassification'], [
|
||||||
('ram:ClassCode', 'code'),
|
('ram:ClassCode', 'code'),
|
||||||
('ram:ClassName', 'name')])
|
('ram:ClassName', 'name')])
|
||||||
|
|
||||||
# serial-numbers of product
|
# serial-numbers of product
|
||||||
result['serialno'] = read_listdata([
|
result['serialno'] = self._readxml_read_listdata(
|
||||||
|
xmldata, xpath_line, [
|
||||||
'ram:SpecifiedTradeProduct',
|
'ram:SpecifiedTradeProduct',
|
||||||
'ram:IndividualTradeProductInstance'], [
|
'ram:IndividualTradeProductInstance'], [
|
||||||
('ram:BatchID', 'lot'),
|
('ram:BatchID', 'lot'),
|
||||||
('ram:SupplierAssignedSerialID', 'serial')])
|
('ram:SupplierAssignedSerialID', 'serial')])
|
||||||
|
|
||||||
# referenced product
|
# referenced product
|
||||||
result['refprod'] = read_listdata(
|
result['refprod'] = self._readxml_read_listdata(
|
||||||
|
xmldata, xpath_line,
|
||||||
['ram:SpecifiedTradeProduct', 'ram:IncludedReferencedProduct'], [
|
['ram:SpecifiedTradeProduct', 'ram:IncludedReferencedProduct'], [
|
||||||
('ram:ID', 'id'),
|
('ram:ID', 'id'),
|
||||||
('ram:GlobalID', 'global_id'),
|
('ram:GlobalID', 'global_id'),
|
||||||
|
@ -775,10 +785,11 @@ class Incoming(metaclass=PoolMeta):
|
||||||
])
|
])
|
||||||
|
|
||||||
# net price
|
# net price
|
||||||
xpath_netprice = xpth + [pos] + [
|
xpath_netprice = xpath_line + [
|
||||||
'ram:SpecifiedLineTradeAgreement', 'ram:NetPriceProductTradePrice']
|
'ram:SpecifiedLineTradeAgreement', 'ram:NetPriceProductTradePrice']
|
||||||
if self._readxml_getvalue(xmldata, xpath_netprice):
|
if self._readxml_getvalue(xmldata, xpath_netprice):
|
||||||
result['unit_net_price'] = read_listdata([
|
result['unit_net_price'] = self._readxml_read_listdata(
|
||||||
|
xmldata, xpath_line, [
|
||||||
'ram:SpecifiedLineTradeAgreement',
|
'ram:SpecifiedLineTradeAgreement',
|
||||||
'ram:NetPriceProductTradePrice'], [
|
'ram:NetPriceProductTradePrice'], [
|
||||||
('ram:ChargeAmount', 'amount', Decimal),
|
('ram:ChargeAmount', 'amount', Decimal),
|
||||||
|
@ -791,11 +802,12 @@ class Incoming(metaclass=PoolMeta):
|
||||||
xpath_netprice + ['ram:AppliedTradeAllowanceCharge']))
|
xpath_netprice + ['ram:AppliedTradeAllowanceCharge']))
|
||||||
|
|
||||||
# gross price
|
# gross price
|
||||||
xpath_grossprice = xpth + [pos] + [
|
xpath_grossprice = xpath_line + [
|
||||||
'ram:SpecifiedLineTradeAgreement',
|
'ram:SpecifiedLineTradeAgreement',
|
||||||
'ram:GrossPriceProductTradePrice']
|
'ram:GrossPriceProductTradePrice']
|
||||||
if self._readxml_getvalue(xmldata, xpath_grossprice):
|
if self._readxml_getvalue(xmldata, xpath_grossprice):
|
||||||
result['unit_gross_price'] = read_listdata([
|
result['unit_gross_price'] = self._readxml_read_listdata(
|
||||||
|
xmldata, xpath_line, [
|
||||||
'ram:SpecifiedLineTradeAgreement',
|
'ram:SpecifiedLineTradeAgreement',
|
||||||
'ram:GrossPriceProductTradePrice'], [
|
'ram:GrossPriceProductTradePrice'], [
|
||||||
('ram:ChargeAmount', 'amount', Decimal),
|
('ram:ChargeAmount', 'amount', Decimal),
|
||||||
|
@ -809,9 +821,10 @@ class Incoming(metaclass=PoolMeta):
|
||||||
['ram:AppliedTradeAllowanceCharge']))
|
['ram:AppliedTradeAllowanceCharge']))
|
||||||
|
|
||||||
# quantity
|
# quantity
|
||||||
xpath_quantity = xpth + [pos] + ['ram:SpecifiedLineTradeDelivery']
|
xpath_quantity = xpath_line + ['ram:SpecifiedLineTradeDelivery']
|
||||||
result['quantity'] = read_listdata(
|
result['quantity'] = self._readxml_read_listdata(
|
||||||
['ram:SpecifiedLineTradeDelivery'], [
|
xmldata, xpath_line, [
|
||||||
|
'ram:SpecifiedLineTradeDelivery'], [
|
||||||
('ram:BilledQuantity', 'billed', Decimal),
|
('ram:BilledQuantity', 'billed', Decimal),
|
||||||
('ram:ChargeFreeQuantity', 'chargefree', Decimal),
|
('ram:ChargeFreeQuantity', 'chargefree', Decimal),
|
||||||
('ram:PackageQuantity', 'package', Decimal),
|
('ram:PackageQuantity', 'package', Decimal),
|
||||||
|
@ -829,8 +842,8 @@ class Incoming(metaclass=PoolMeta):
|
||||||
'skip: ' + self._readxml_xpath(xp_to_check))
|
'skip: ' + self._readxml_xpath(xp_to_check))
|
||||||
|
|
||||||
# taxes
|
# taxes
|
||||||
xpath_trade = xpth + [pos] + ['ram:SpecifiedLineTradeSettlement']
|
xpath_trade = xpath_line + ['ram:SpecifiedLineTradeSettlement']
|
||||||
result['taxes'] = read_listdata([
|
result['taxes'] = self._readxml_read_listdata(xmldata, xpath_line, [
|
||||||
'ram:SpecifiedLineTradeSettlement',
|
'ram:SpecifiedLineTradeSettlement',
|
||||||
'ram:ApplicableTradeTax'], [
|
'ram:ApplicableTradeTax'], [
|
||||||
('ram:CalculatedAmount', 'amount', Decimal),
|
('ram:CalculatedAmount', 'amount', Decimal),
|
||||||
|
@ -846,7 +859,7 @@ class Incoming(metaclass=PoolMeta):
|
||||||
('ram:RateApplicablePercent', 'percent', Decimal)])
|
('ram:RateApplicablePercent', 'percent', Decimal)])
|
||||||
|
|
||||||
# total amounts
|
# total amounts
|
||||||
result['total'] = read_listdata([
|
result['total'] = self._readxml_read_listdata(xmldata, xpath_line, [
|
||||||
'ram:SpecifiedLineTradeSettlement',
|
'ram:SpecifiedLineTradeSettlement',
|
||||||
'ram:SpecifiedTradeSettlementLineMonetarySummation'], [
|
'ram:SpecifiedTradeSettlementLineMonetarySummation'], [
|
||||||
('ram:LineTotalAmount', 'amount', Decimal),
|
('ram:LineTotalAmount', 'amount', Decimal),
|
||||||
|
|
Loading…
Reference in a new issue