-
Notifications
You must be signed in to change notification settings - Fork 132
Open [IMP] account_exchange_difference_invoice: Add demo data (approach 2) #860
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| from . import models | ||
| from . import wizards | ||
| from . import demo |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| from . import account_exchange_demo |
154 changes: 154 additions & 0 deletions
154
account_exchange_difference_invoice/demo/account_exchange_demo.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,154 @@ | ||
| import logging | ||
|
|
||
| from dateutil.relativedelta import relativedelta | ||
| from odoo import Command, api, fields, models | ||
|
|
||
| _logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class AccountChartTemplate(models.AbstractModel): | ||
| _inherit = "account.chart.template" | ||
|
|
||
| @api.model | ||
| def _install_exchange_diff_demo(self, companies): | ||
| """Crea data demo para probar este modulo. | ||
| La idea es usar esté método también para instanciar la data de tests. | ||
| Por ahora está utilizando algo de data demo (l10n_ar_tax.res_partner_adhoc_caba, product.product_product_2) | ||
| Eventualemnte, para que los tests NO dependan de data demo, podriamos antes de llamar a este método | ||
| verificar si existen esos registros y crearlos si no existen con esos xmlids para que funcione bien. | ||
| """ | ||
| for company in companies.filtered(lambda x: x.country_code == "AR"): | ||
| _logger.info("Creating exchange demo data for company: %s", company.name) | ||
| self = self.with_company(company) | ||
|
|
||
| demo_data = { | ||
| "res.currency.rate": self._exchange_diff_invoice_demo_rates(), | ||
| "account.move": self._exchange_diff_invoice_demo_invoices(), | ||
| "account.journal": self._exchange_diff_invoice_demo_journals(), | ||
| } | ||
|
|
||
| # skip_readonly_check es solo para poder hacer pruebas de volver a cargar data | ||
| self.sudo().with_context(skip_pdf_attachment_generation=True, skip_readonly_check=True)._load_data( | ||
| demo_data | ||
| ) | ||
| self._exchange_diff_invoice_demo_post_invoices() | ||
| self._exchange_diff_invoice_demo_create_payments() | ||
|
|
||
| @api.model | ||
| def _exchange_diff_invoice_demo_rates(self): | ||
| first_day_of_month = fields.Date.today() + relativedelta(day=1) | ||
| rates = [1000, 1100, 1200, 1300] # 01, 02, 03, 04 of actual month | ||
| rates_data = {} | ||
| for days_ago, rate_value in enumerate(rates): | ||
| date_value = first_day_of_month + relativedelta(days=days_ago) | ||
| rates_data[f"exchange_rate_{days_ago}"] = { | ||
| "currency_id": "base.USD", | ||
| "name": date_value.isoformat(), | ||
| "rate": 1 / rate_value, | ||
| } | ||
| return rates_data | ||
|
|
||
| @api.model | ||
| def _exchange_diff_invoice_demo_invoices(self): | ||
| """Create demo invoices in USD with specific amounts and tax breakdown.""" | ||
| first_day_of_month = fields.Date.today() + relativedelta(day=1) | ||
| return { | ||
| "demo_invoice_1": { | ||
| "move_type": "out_invoice", | ||
| "partner_id": "l10n_ar_tax.res_partner_adhoc_caba", | ||
| "currency_id": "base.USD", | ||
| "invoice_date": first_day_of_month, | ||
| "invoice_line_ids": [Command.create({"product_id": "product.product_product_2", "quantity": 1})], | ||
| }, | ||
| "demo_invoice_2": { | ||
| "move_type": "out_invoice", | ||
| "partner_id": "l10n_ar_tax.res_partner_adhoc_caba", | ||
| "currency_id": "base.USD", | ||
| "invoice_date": first_day_of_month + relativedelta(days=1), | ||
| "invoice_line_ids": [Command.create({"product_id": "product.product_product_2", "quantity": 1})], | ||
| }, | ||
| "demo_invoice_3": { | ||
| "move_type": "out_invoice", | ||
| "partner_id": "l10n_ar_tax.res_partner_adhoc_caba", | ||
| "currency_id": "base.USD", | ||
| "invoice_date": first_day_of_month + relativedelta(days=2), | ||
| "invoice_line_ids": [Command.create({"product_id": "product.product_product_2", "quantity": 1})], | ||
| }, | ||
| # otro partner y otra jurisdicción | ||
| "demo_invoice_4": { | ||
| "move_type": "out_invoice", | ||
| "partner_id": "l10n_ar.res_partner_gritti_agrimensura", | ||
| "currency_id": "base.USD", | ||
| "invoice_date": first_day_of_month, | ||
| "invoice_line_ids": [Command.create({"product_id": "product.product_product_2", "quantity": 1})], | ||
| }, | ||
| } | ||
|
|
||
| @api.model | ||
| def _exchange_diff_invoice_demo_post_invoices(self): | ||
| invoices = self.env["account.move"] | ||
| for xmlid in self._exchange_diff_invoice_demo_invoices().keys(): | ||
| invoices |= self.ref(xmlid) | ||
| invoices.filtered(lambda m: m.state == "draft").action_post() | ||
|
|
||
| @api.model | ||
| def _exchange_diff_invoice_demo_create_payments(self): | ||
| first_day_of_month = fields.Date.today() + relativedelta(day=1) | ||
| for invoices_xml_ids, payment_date in [ | ||
| (["demo_invoice_1", "demo_invoice_2"], first_day_of_month + relativedelta(days=2)), | ||
| (["demo_invoice_3"], first_day_of_month + relativedelta(days=3)), | ||
| (["demo_invoice_4"], first_day_of_month + relativedelta(days=1)), | ||
| ]: | ||
| invoices = self.env["account.move"] | ||
| for xmlid in invoices_xml_ids: | ||
| invoices |= self.ref(xmlid) | ||
|
|
||
| amount_residual = sum(invoices.mapped("amount_residual")) | ||
| if not amount_residual: | ||
| continue | ||
|
|
||
| l10n_ar_withholding_vals = [] | ||
| # para facturas de clientes las retenciones se agregan manualmente | ||
| # ACTIVAR CUANDO TENGAMOS SOPORTADAS LAS RETENCIONES EN USD | ||
| # if invoices[0].move_type == "out_invoice": | ||
| # withholding_amount = 1.1 | ||
| # # para jugar con distintos casos usamos la provincia del cliente y suponemos que nos retiene de la misma jurisdicción | ||
| # tax = self.env["account.tax"].search( | ||
| # [ | ||
| # ("company_id", "=", invoices[0].company_id.id), | ||
| # ("l10n_ar_state_id", "!=", invoices[0].partner_id.state_id.id), | ||
| # ("l10n_ar_state_id.country_id.code", "=", "AR"), | ||
| # ("l10n_ar_withholding_payment_type", "=", "customer"), | ||
| # ], | ||
| # limit=1, | ||
| # ) | ||
| # l10n_ar_withholding_vals = [ | ||
| # Command.create( | ||
| # { | ||
| # "name": "0001-00000001", | ||
| # "tax_id": tax.id, | ||
| # "amount": withholding_amount, | ||
| # } | ||
| # ) | ||
| # ] | ||
| # amount_residual -= withholding_amount | ||
|
|
||
| vals = { | ||
| "amount": amount_residual, | ||
| "date": payment_date, | ||
| "journal_id": self.ref("demo_cash_usd").id, | ||
| "l10n_ar_withholding_line_ids": l10n_ar_withholding_vals, | ||
| } | ||
| action_context = invoices.action_register_payment()["context"] | ||
| payment = self.env["account.payment"].with_context(**action_context).create(vals) | ||
| payment.action_post() | ||
|
|
||
| @api.model | ||
| def _exchange_diff_invoice_demo_journals(self): | ||
| return { | ||
| "demo_cash_usd": { | ||
| "name": "Caja USD", | ||
| "type": "cash", | ||
| "currency_id": "base.USD", | ||
| }, | ||
| } | ||
6 changes: 6 additions & 0 deletions
6
account_exchange_difference_invoice/demo/account_exchange_demo.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <odoo> | ||
| <function model="account.chart.template" name="_install_exchange_diff_demo"> | ||
| <value model="res.company" eval="obj().env.ref('base.company_ri')"/> | ||
| </function> | ||
| </odoo> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Se llama al método
_exchange_diff_invoice_demo_create_payments()pero este no está definido en ninguna parte del código. Esto causará unAttributeErrorcuando se ejecute el demo. Si la funcionalidad está comentada más abajo (líneas 74-138), deberías eliminar esta línea o descomentar e implementar el método correspondiente.