Merge branch 'master-upstream-patch-02122021' into 'master'

[PATCH] Upstream patch - 02122021

See merge request flectra-hq/flectra!515
This commit is contained in:
Parthiv Patel committed 2021-12-03 05:34:43 +00:00
commit 4f2062025b
5 files changed
+134 -23

No files matched your search

+17 -10
View File
@@ -117,6 +117,7 @@ class AccountEdiFormat(models.Model):
:returns: A dictionary {'name': name, 'datas': datas} or False if there are no values to embed.
* name: The name of the file.
* datas: The bytes ot the file.
To remove in master
"""
self.ensure_one()
attachment = invoice._get_edi_attachment(self)
@@ -287,6 +288,17 @@ class AccountEdiFormat(models.Model):
self.ensure_one()
return self.env['account.move']
def _prepare_invoice_report(self, pdf_writer, edi_document):
"""
Prepare invoice report to be printed.
:param pdf_writer: The pdf writer with the invoice pdf content loaded.
:param edi_document: The edi document to be added to the pdf file.
"""
# TO OVERRIDE
self.ensure_one()
if self._is_embedding_to_invoice_pdf_needed():
pdf_writer.embed_flectra_attachment(edi_document.attachment_id)
####################################################
# Export Internal methods (not meant to be overridden)
####################################################
@@ -298,20 +310,15 @@ class AccountEdiFormat(models.Model):
:param invoice: the invoice to generate the EDI from.
:returns: the same pdf_content with the EDI of the invoice embed in it.
"""
attachments = []
for edi_format in self.filtered(lambda edi_format: edi_format._is_embedding_to_invoice_pdf_needed()):
attach = edi_format._get_embedding_to_invoice_pdf_values(invoice)
if attach:
attachments.append(attach)
if attachments:
# Add the attachments to the pdf file
to_embed = invoice.edi_document_ids
# Add the attachments to the pdf file
if to_embed:
reader_buffer = io.BytesIO(pdf_content)
reader = FlectraPdfFileReader(reader_buffer, strict=False)
writer = FlectraPdfFileWriter()
writer.cloneReaderDocumentRoot(reader)
for vals in attachments:
writer.addAttachment(vals['name'], vals['datas'])
for edi_document in to_embed:
edi_document.edi_format_id._prepare_invoice_report(writer, edi_document)
buffer = io.BytesIO()
writer.write(buffer)
pdf_content = buffer.getvalue()
@@ -231,5 +231,88 @@
</rsm:SupplyChainTradeTransaction>
</rsm:CrossIndustryInvoice>
</template>
<template id="account_invoice_pdfa_3_facturx_metadata">
<x:xmpmeta xmlns:x="adobe:ns:meta/">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description xmlns:pdfaid="http://www.aiim.org/pdfa/ns/id/" rdf:about="">
<pdfaid:part>3</pdfaid:part>
<pdfaid:conformance>B</pdfaid:conformance>
</rdf:Description>
<rdf:Description xmlns:dc="http://purl.org/dc/elements/1.1/" rdf:about="">
<dc:title>
<rdf:Alt>
<rdf:li t-att="{'xml:lang': 'x-default'}" t-esc="title"/>
</rdf:Alt>
</dc:title>
<dc:creator>
<rdf:Seq>
<rdf:li>Flectra</rdf:li>
</rdf:Seq>
</dc:creator>
<dc:description>
<rdf:Alt>
<rdf:li t-att="{'xml:lang': 'x-default'}">Invoice generated by Flectra</rdf:li>
</rdf:Alt>
</dc:description>
</rdf:Description>
<rdf:Description xmlns:pdf="http://ns.adobe.com/pdf/1.3/" rdf:about="">
<pdf:Producer>Flectra</pdf:Producer>
</rdf:Description>
<rdf:Description xmlns:xmp="http://ns.adobe.com/xap/1.0/" rdf:about="">
<xmp:CreatorTool>Flectra</xmp:CreatorTool>
<xmp:CreateDate t-esc="date"/>
<xmp:ModifyDate t-esc="date"/>
</rdf:Description>
<rdf:Description xmlns:pdfaExtension="http://www.aiim.org/pdfa/ns/extension/"
xmlns:pdfaSchema="http://www.aiim.org/pdfa/ns/schema#"
xmlns:pdfaProperty="http://www.aiim.org/pdfa/ns/property#" rdf:about="">
<pdfaExtension:schemas>
<rdf:Bag>
<rdf:li rdf:parseType="Resource">
<pdfaSchema:schema>Factur-X PDFA Extension Schema</pdfaSchema:schema>
<pdfaSchema:namespaceURI>urn:factur-x:pdfa:CrossIndustryDocument:invoice:1p0#</pdfaSchema:namespaceURI>
<pdfaSchema:prefix>fx</pdfaSchema:prefix>
<pdfaSchema:property>
<rdf:Seq>
<rdf:li rdf:parseType="Resource">
<pdfaProperty:name>DocumentFileName</pdfaProperty:name>
<pdfaProperty:valueType>Text</pdfaProperty:valueType>
<pdfaProperty:category>external</pdfaProperty:category>
<pdfaProperty:description>name of the embedded XML invoice file</pdfaProperty:description>
</rdf:li>
<rdf:li rdf:parseType="Resource">
<pdfaProperty:name>DocumentType</pdfaProperty:name>
<pdfaProperty:valueType>Text</pdfaProperty:valueType>
<pdfaProperty:category>external</pdfaProperty:category>
<pdfaProperty:description>INVOICE</pdfaProperty:description>
</rdf:li>
<rdf:li rdf:parseType="Resource">
<pdfaProperty:name>Version</pdfaProperty:name>
<pdfaProperty:valueType>Text</pdfaProperty:valueType>
<pdfaProperty:category>external</pdfaProperty:category>
<pdfaProperty:description>The actual version of the Factur-X XML schema</pdfaProperty:description>
</rdf:li>
<rdf:li rdf:parseType="Resource">
<pdfaProperty:name>ConformanceLevel</pdfaProperty:name>
<pdfaProperty:valueType>Text</pdfaProperty:valueType>
<pdfaProperty:category>external</pdfaProperty:category>
<pdfaProperty:description>The conformance level of the embedded Factur-X data</pdfaProperty:description>
</rdf:li>
</rdf:Seq>
</pdfaSchema:property>
</rdf:li>
</rdf:Bag>
</pdfaExtension:schemas>
</rdf:Description>
<rdf:Description xmlns:fx="urn:factur-x:pdfa:CrossIndustryDocument:invoice:1p0#" rdf:about="">
<fx:ConformanceLevel>EN 16931</fx:ConformanceLevel>
<fx:DocumentFileName>factur-x.xml</fx:DocumentFileName>
<fx:DocumentType>INVOICE</fx:DocumentType>
<fx:Version>1.0</fx:Version>
</rdf:Description>
</rdf:RDF>
</x:xmpmeta>
</template>
</data>
</flectra>
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from flectra import api, models, fields, tools, _
from flectra.tools import DEFAULT_SERVER_DATE_FORMAT, float_repr
from flectra.tools import DEFAULT_SERVER_DATE_FORMAT, float_repr, str2bool
from flectra.tests.common import Form
from flectra.exceptions import UserError
@@ -51,6 +51,24 @@ class AccountEdiFormat(models.Model):
values['name'] = 'factur-x.xml'
return values
def _prepare_invoice_report(self, pdf_writer, edi_document):
self.ensure_one()
if self.code != 'facturx_1_0_05':
super()._prepare_invoice_report(pdf_writer, edi_document)
pdf_writer.embed_flectra_attachment(edi_document.attachment_id)
if not pdf_writer.is_pdfa and str2bool(self.env['ir.config_parameter'].sudo().get_param('edi.use_pdfa', 'False')):
try:
pdf_writer.convert_to_pdfa()
except Exception as e:
_logger.exception("Error while converting to PDF/A: %s", e)
metadata_template = self.env.ref('account_edi_facturx.account_invoice_pdfa_3_facturx_metadata', raise_if_not_found=False)
if metadata_template:
pdf_writer.add_file_metadata(metadata_template._render({
'title': edi_document.move_id.name,
'date': fields.Date.context_today(self),
}))
def _export_facturx(self, invoice):
def format_date(dt):
@@ -114,11 +132,10 @@ class AccountEdiFormat(models.Model):
xml_content = b"<?xml version='1.0' encoding='UTF-8'?>"
xml_content += self.env.ref('account_edi_facturx.account_invoice_facturx_export')._render(template_values)
xml_name = '%s_facturx.xml' % (invoice.name.replace('/', '_'))
return self.env['ir.attachment'].create({
'name': xml_name,
'name': 'factur-x.xml',
'datas': base64.encodebytes(xml_content),
'mimetype': 'application/xml'
'mimetype': '/application#2Fxml'
})
def _is_facturx(self, filename, tree):
+11 -8
View File
@@ -131,7 +131,7 @@ class RecurrenceRule(models.Model):
def _compute_name(self):
for recurrence in self:
period = dict(RRULE_TYPE_SELECTION)[recurrence.rrule_type]
every = _("Every %(count)s %(period)s, ", count=recurrence.interval, period=period)
every = _("Every %(count)s %(period)s", count=recurrence.interval, period=period)
if recurrence.end_type == 'count':
end = _("for %s events", recurrence.count)
@@ -140,19 +140,22 @@ class RecurrenceRule(models.Model):
else:
end = ''
if recurrence.rrule_type == 'weeky':
if recurrence.rrule_type == 'weekly':
weekdays = recurrence._get_week_days()
weekday_fields = (self._fields[weekday_to_field(w)] for w in weekdays)
on = _("on %s,") % ", ".join([field.string for field in weekday_fields])
# Convert Weekday object
weekdays = [str(w) for w in weekdays]
day_strings = [d[1] for d in WEEKDAY_SELECTION if d[0] in weekdays]
on = _("on %s") % ", ".join([day_name for day_name in day_strings])
elif recurrence.rrule_type == 'monthly':
if recurrence.month_by == 'day':
weekday_label = dict(BYDAY_SELECTION)[recurrence.byday]
on = _("on the %(position)s %(weekday)s, ", position=recurrence.byday, weekday=weekday_label)
position_label = dict(BYDAY_SELECTION)[recurrence.byday]
weekday_label = dict(WEEKDAY_SELECTION)[recurrence.weekday]
on = _("on the %(position)s %(weekday)s", position=position_label, weekday=weekday_label)
else:
on = _("day %s, ", recurrence.day)
on = _("day %s", recurrence.day)
else:
on = ''
recurrence.name = every + on + end
recurrence.name = ', '.join(filter(lambda s: s, [every, on, end]))
@api.depends('calendar_event_ids.start')
def _compute_dtstart(self):
+2 -1
View File
@@ -41,7 +41,8 @@ class TestAccountFrFec(AccountTestInvoicingCommon):
cls.wizard = cls.env['account.fr.fec'].create({
'date_from': fields.Date.today() - timedelta(days=1),
'date_to': fields.Date.today(),
'export_type': 'official'
'export_type': 'official',
'test_file': True,
})
def test_generate_fec_sanitize_pieceref(self):