Skip to content

Commit

Permalink
[ADD] base_import_pdf_by_template_account: New module
Browse files Browse the repository at this point in the history
TT50003
  • Loading branch information
victoralmau committed Oct 30, 2024
1 parent 5c09daf commit 873ec82
Show file tree
Hide file tree
Showing 24 changed files with 1,067 additions and 186 deletions.
12 changes: 12 additions & 0 deletions base_import_pdf_by_template/security/security.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,16 @@
name="domain_force"
>[('template_id.company_id', 'in', [False] + company_ids)]</field>
</record>
<record id="rule_base_import_pdf_template_see_all" model="ir.rule">
<field name="name">All Base Import Pdf Templates</field>
<field name="model_id" ref="model_base_import_pdf_template" />
<field name="domain_force">[(1, '=', 1)]</field>
<field name="groups" eval="[(4, ref('base.group_no_one'))]" />
</record>
<record id="rule_base_import_pdf_template_line_see_all" model="ir.rule">
<field name="name">All Base Import Pdf Template Lines</field>
<field name="model_id" ref="model_base_import_pdf_template_line" />
<field name="domain_force">[(1, '=', 1)]</field>
<field name="groups" eval="[(4, ref('base.group_no_one'))]" />
</record>
</odoo>
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class WizardBaseImportPdfUpload(models.TransientModel):
_description = "Wizard Base Import Pdf Upload"

model = fields.Char()
record_ref = fields.Reference(selection="_selection_reference_value")
attachment_ids = fields.Many2many(comodel_name="ir.attachment", string="Files")
allowed_template_ids = fields.Many2many(
comodel_name="base.import.pdf.template", compute="_compute_allowed_template_ids"
Expand All @@ -26,6 +27,15 @@ class WizardBaseImportPdfUpload(models.TransientModel):
inverse_name="parent_id",
)

@api.model
def _selection_reference_value(self):
models = (
self.env["ir.model"]
.sudo()
.search([("transient", "=", False)], order="name asc")
)
return [(model.model, model.name) for model in models]

@api.depends("model")
def _compute_allowed_template_ids(self):
template_model = self.env["base.import.pdf.template"]
Expand Down Expand Up @@ -179,6 +189,7 @@ def _process_form(self):
text = self.data
template = self.template_id
model = self.env[template.model]
model = self.parent_id.record_ref or self.env[template.model]
ctx = template._prepare_ctx_from_model(template.model)
model_form = Form(model.with_context(**ctx))
# Set the values of the header in Form
Expand Down Expand Up @@ -216,9 +227,16 @@ def _process_form(self):
for key in ctx:
if key.startswith("default_"):
field = key.replace("default_", "")
if field in vals:
if field in vals and not self.parent_id.record_ref:
vals.update({field: ctx[key]})
elif self.parent_id.record_ref:
vals.update({field: ctx[key]})
record = model.with_context(**ctx).create(vals)
# Create or update
if self.parent_id.record_ref:
model.with_context(**ctx).write(vals)
record = self.parent_id.record_ref
else:
record = model.with_context(**ctx).create(vals)
except AssertionError as err:
raise UserError(err) from err
if self.log_text:
Expand Down
90 changes: 90 additions & 0 deletions base_import_pdf_by_template_account/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
===================================
Base Import Pdf by Template Account
===================================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:6b053ca4747568743800079faebd557c69331b093cf1a6bc25fa9886d022dd66
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fedi-lightgray.png?logo=github
:target: https://github.com/OCA/edi/tree/17.0/base_import_pdf_by_template_account
:alt: OCA/edi
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/edi-17-0/edi-17-0-base_import_pdf_by_template_account
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/edi&target_branch=17.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

Added support for account to process the PDF attached to the invoice
when creating the invoice from an email alias. Add 'Invoicing >
Configuration > Management > Invoice Templates' menu item to Manager
Accounting users.

**Table of contents**

.. contents::
:local:

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/edi/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/edi/issues/new?body=module:%20base_import_pdf_by_template_account%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
-------

* Tecnativa

Contributors
------------

- `Tecnativa <https://www.tecnativa.com>`__:

- Víctor Martínez
- Pedro M. Baeza

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

.. |maintainer-victoralmau| image:: https://github.com/victoralmau.png?size=40px
:target: https://github.com/victoralmau
:alt: victoralmau

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-victoralmau|

This module is part of the `OCA/edi <https://github.com/OCA/edi/tree/17.0/base_import_pdf_by_template_account>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions base_import_pdf_by_template_account/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
20 changes: 20 additions & 0 deletions base_import_pdf_by_template_account/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2024 Tecnativa - Víctor Martínez
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Base Import Pdf by Template Account",
"version": "17.0.1.0.0",
"website": "https://github.com/OCA/edi",
"author": "Tecnativa, Odoo Community Association (OCA)",
"license": "AGPL-3",
"depends": ["account", "base_import_pdf_by_template"],
"installable": True,
"demo": [
"demo/base_import_pdf_template.xml",
],
"data": [
"security/ir.model.access.csv",
"security/security.xml",
"views/base_import_pdf_template_views.xml",
],
"maintainers": ["victoralmau"],
}
155 changes: 155 additions & 0 deletions base_import_pdf_by_template_account/demo/base_import_pdf_template.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo noupdate="1">
<record id="generic_product" model="product.product">
<field name="name">Test Generic Product</field>
<field name="default_code">GENERIC</field>
</record>
<!-- Account invoice Template Data !-->
<record id="partner_tecnativa" model="res.partner">
<field name="name">Tecnativa</field>
</record>
<record id="supplierinfo_tecnativa_CONS_0001" model="product.supplierinfo">
<field name="partner_id" ref="partner_tecnativa" />
<field name="product_code">CONS_0001</field>
</record>
<record id="product_rotulador" model="product.product">
<field name="name">Test Rotulador</field>
<field name="default_code">ROTULADOR</field>
<field name="purchase_ok" eval="True" />
<field
name="seller_ids"
eval="[(6, 0, [ref('supplierinfo_tecnativa_CONS_0001')])]"
/>
</record>
<record id="supplierinfo_tecnativa_CONS_0002" model="product.supplierinfo">
<field name="partner_id" ref="partner_tecnativa" />
<field name="product_code">CONS_0002</field>
</record>
<record id="product_boligrafo" model="product.product">
<field name="name">Test Boligrafo</field>
<field name="default_code">BOLIGRAFO</field>
<field name="purchase_ok" eval="True" />
<field
name="seller_ids"
eval="[(6, 0, [ref('supplierinfo_tecnativa_CONS_0002')])]"
/>
</record>
<record id="supplierinfo_tecnativa_FURN_0003" model="product.supplierinfo">
<field name="partner_id" ref="partner_tecnativa" />
<field name="product_code">FURN_0003</field>
</record>
<record id="product_leds" model="product.product">
<field name="name">Test Leds</field>
<field name="default_code">LEDS</field>
<field name="purchase_ok" eval="True" />
<field
name="seller_ids"
eval="[(6, 0, [ref('supplierinfo_tecnativa_FURN_0003')])]"
/>
</record>
<record id="supplierinfo_tecnativa_E_COM10" model="product.supplierinfo">
<field name="partner_id" ref="partner_tecnativa" />
<field name="product_code">E-COM10</field>
</record>
<record id="product_plastificadora" model="product.product">
<field name="name">Test Plastificadora</field>
<field name="default_code">PLASTIFICADORA</field>
<field name="purchase_ok" eval="True" />
<field
name="seller_ids"
eval="[(6, 0, [ref('supplierinfo_tecnativa_E_COM10')])]"
/>
</record>
<record id="supplierinfo_tecnativa_FURN_8621" model="product.supplierinfo">
<field name="partner_id" ref="partner_tecnativa" />
<field name="product_code">FURN_8621</field>
</record>
<record id="product_laminas" model="product.product">
<field name="name">Test Lmaninas</field>
<field name="default_code">LAMINAS</field>
<field name="purchase_ok" eval="True" />
<field
name="seller_ids"
eval="[(6, 0, [ref('supplierinfo_tecnativa_FURN_8621')])]"
/>
</record>
<record id="supplierinfo_tecnativa_FURN_7023" model="product.supplierinfo">
<field name="partner_id" ref="partner_tecnativa" />
<field name="product_code">FURN_7023</field>
</record>
<record id="product_trituradora" model="product.product">
<field name="name">Test Trituradora</field>
<field name="default_code">TRITURADORA</field>
<field name="purchase_ok" eval="True" />
<field
name="seller_ids"
eval="[(6, 0, [ref('supplierinfo_tecnativa_FURN_7023')])]"
/>
</record>
<record id="invoice_tecnativa" model="base.import.pdf.template">
<field name="name">Invoices Tecnativa</field>
<field name="model_id" ref="account.model_account_move" />
<field
name="child_field_id"
ref="account.field_account_move__invoice_line_ids"
/>
<!-- <field name="auto_detect_pattern">(?<=B 8 7 5 3 0 4 3 2)[\S\s]*</field> -->
<field name="header_items">Producto,Cantidad,Precio</field>
</record>
<record
id="invoice_tecnativa_line_partner_id"
model="base.import.pdf.template.line"
>
<field name="template_id" ref="invoice_tecnativa" />
<field name="related_model">header</field>
<field name="field_id" ref="account.field_account_move__partner_id" />
<field name="value_type">fixed</field>
<field name="fixed_value" ref="partner_tecnativa" />
</record>
<record id="invoice_tecnativa_line_move_type" model="base.import.pdf.template.line">
<field name="template_id" ref="invoice_tecnativa" />
<field name="related_model">header</field>
<field name="field_id" ref="account.field_account_move__move_type" />
<field name="value_type">fixed</field>
<field
name="fixed_value_selection"
ref="account.selection__account_invoice_report__move_type__in_invoice"
/>
</record>
<record
id="invoice_tecnativa_line_product_id"
model="base.import.pdf.template.line"
>
<field name="template_id" ref="invoice_tecnativa" />
<field name="related_model">lines</field>
<field name="field_id" ref="account.field_account_move_line__product_id" />
<field name="column">0</field>
<field name="pattern">\[([A-Z\d]+[_|-][A-Z\d]+)\]</field>
<field name="value_type">variable</field>
<field name="search_field_id" ref="product.field_product_product__seller_ids" />
<field
name="search_subfield_id"
ref="product.field_product_supplierinfo__product_code"
/>
<!-- <field name="default_value">product.product,cls.env.ref('base_import_pdf_by_template_account.generic_product').id</field> -->
</record>
<record id="invoice_tecnativa_line_quantity" model="base.import.pdf.template.line">
<field name="template_id" ref="invoice_tecnativa" />
<field name="related_model">lines</field>
<field name="field_id" ref="account.field_account_move_line__quantity" />
<field name="column">1</field>
<field name="pattern">\[[A-Z\d]+[_|-][A-Z\d]+\] [a-zA-Záí]* ([0-9]{1,3})</field>
<field name="value_type">variable</field>
</record>
<record id="invoice_tecnativa_price_unit" model="base.import.pdf.template.line">
<field name="template_id" ref="invoice_tecnativa" />
<field name="related_model">lines</field>
<field name="field_id" ref="account.field_account_move_line__price_unit" />
<field name="column">2</field>
<field
name="pattern"
>\[[A-Z\d]+[_|-][A-Z\d]+\] [a-zA-Záí]* [0-9]{1,3} ([0-9]{1,3}.[0-9]{2})</field>
<field name="value_type">variable</field>
<field name="log_distinct_value" eval="True" />
</record>
</odoo>
Loading

0 comments on commit 873ec82

Please sign in to comment.