Skip to content

Commit

Permalink
Merge PR #1056 into 17.0
Browse files Browse the repository at this point in the history
Signed-off-by pedrobaeza
  • Loading branch information
OCA-git-bot committed Dec 24, 2024
2 parents 47b3296 + 4569fb1 commit d4cfdf0
Show file tree
Hide file tree
Showing 26 changed files with 1,245 additions and 193 deletions.
12 changes: 11 additions & 1 deletion base_import_pdf_by_template/models/base_import_pdf_template.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright 2024 Tecnativa - Víctor Martínez
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
import json
import re
from datetime import datetime

Expand Down Expand Up @@ -238,12 +239,18 @@ class BaseImportPdfTemplateLine(models.Model):
selection=[
("*Y-*d-*m", _("YY-dd-MM")),
("*m-*d-*Y", _("MM-dd-YY")),
("*d-*m-*Y", _("dd-MM-YY")),
("*Y/*d/*m", _("YY/dd/MM")),
("*m/*d/*Y", _("MM/dd/YY")),
("*d.*m.*Y", _("dd.MM.YY")),
("*d.*m.*y-short", _("dd.MM.yy")),
("*d/*m/*Y", _("dd/MM/YY")),
("*d/*m/*y-short", _("dd/MM/yy")),
("*B *d, *Y", _("B d, YY")),
("*B *d, *Y", _("B dd, YY")),
("*b-short *d, *Y", _("b dd, YY")),
("*d *b-short *Y", _("dd b YY")),
("*d *B *Y", _("dd B YY")),
("*d-*b-*y", _("dd-b-yy")),
],
)
time_format = fields.Selection(
Expand Down Expand Up @@ -338,6 +345,7 @@ def _get_fixed_field_name_ttype_mapped(self):
"integer": "fixed_value_integer",
"selection": "fixed_value_selection",
"text": "fixed_value_text",
"json": "fixed_value_text",
"many2one": "fixed_value",
}

Expand All @@ -347,6 +355,8 @@ def _get_fixed_value(self):
f_value = self[f_name]
if self.field_ttype == "selection":
f_value = f_value.value
elif self.field_ttype == "json":
f_value = json.loads(f_value)
return f_value

def _replace_text(self, text, letters, prefix):
Expand Down
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 @@ -101,7 +101,7 @@
<field
name="fixed_value_text"
string="Fixed value"
invisible="value_type != 'fixed' or field_ttype != 'text'"
invisible="value_type != 'fixed' or field_ttype not in ('text', 'json')"
/>
<field
name="fixed_value"
Expand Down
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"],
}
Loading

0 comments on commit d4cfdf0

Please sign in to comment.