Skip to content

Commit

Permalink
pre-commit automatic changes
Browse files Browse the repository at this point in the history
closes #225

Signed-off-by: Virginia Bonservizi <[email protected]>
  • Loading branch information
jue-adhoc committed Feb 5, 2025
1 parent 6e16923 commit 99b1a15
Show file tree
Hide file tree
Showing 21 changed files with 594 additions and 614 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

exclude: |
(?x)
# We don't want to mess with tool-generated files
.svg$|/tests/([^/]+/)?cassettes/|^.copier-answers.yml$|^.github/|^eslint.config.cjs|^prettier.config.cjs|
# Library files can have extraneous formatting (even minimized)
Expand Down
46 changes: 22 additions & 24 deletions l10n_ar_sale/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
{
'name': 'Argentinian Sale Total Fields',
'version': "18.0.1.0.0",
'category': 'Localization/Argentina',
'sequence': 14,
'author': 'ADHOC SA',
'website': 'www.adhoc.com.ar',
'license': 'AGPL-3',
'summary': '',
'depends': [
'sale',
'l10n_ar_tax',
"name": "Argentinian Sale Total Fields",
"version": "18.0.1.0.0",
"category": "Localization/Argentina",
"sequence": 14,
"author": "ADHOC SA",
"website": "www.adhoc.com.ar",
"license": "AGPL-3",
"summary": "",
"depends": [
"sale",
"l10n_ar_tax",
],
'external_dependencies': {
},
'data': [
'security/invoice_sale_security.xml',
'views/sale_view.xml',
'views/l10n_ar_sale_templates.xml',
'views/sale_report_templates.xml',
'wizards/res_config_settings_view.xml',
"external_dependencies": {},
"data": [
"security/invoice_sale_security.xml",
"views/sale_view.xml",
"views/l10n_ar_sale_templates.xml",
"views/sale_report_templates.xml",
"wizards/res_config_settings_view.xml",
],
'demo': [
],
'installable': True,
'auto_install': False,
'application': False,
"demo": [],
"installable": True,
"auto_install": False,
"application": False,
}
51 changes: 29 additions & 22 deletions l10n_ar_sale/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,77 +2,84 @@
# For copyright and license notices, see __manifest__.py file in module root
# directory
##############################################################################
from odoo import models, fields, api, _
import json
import logging

from odoo import api, fields, models

_logger = logging.getLogger(__name__)


class SaleOrder(models.Model):
_inherit = "sale.order"

vat_discriminated = fields.Boolean(
compute='_compute_vat_discriminated',
compute="_compute_vat_discriminated",
)

@api.depends(
'partner_id.l10n_ar_afip_responsibility_type_id',
'company_id.l10n_ar_company_requires_vat',)
"partner_id.l10n_ar_afip_responsibility_type_id",
"company_id.l10n_ar_company_requires_vat",
)
def _compute_vat_discriminated(self):
for rec in self:
rec.vat_discriminated = rec.company_id.l10n_ar_company_requires_vat and \
rec.partner_id.l10n_ar_afip_responsibility_type_id.code in ['1'] or False
rec.vat_discriminated = (
rec.company_id.l10n_ar_company_requires_vat
and rec.partner_id.l10n_ar_afip_responsibility_type_id.code in ["1"]
or False
)

def _compute_tax_totals(self):
super()._compute_tax_totals()
# discriminamos o no impuestos solo en pdf y portal. En backend siempre los mostramos. Para esto evaluamos:
# commit_assetsbundle viene cuando sacamos pdf
# portal_view lo mandamos cuando mostramos campo en portal
report_or_portal_view = 'commit_assetsbundle' in self.env.context or 'from_portal_view' in self.env.context
report_or_portal_view = "commit_assetsbundle" in self.env.context or "from_portal_view" in self.env.context
if not report_or_portal_view:
return

for order in self.filtered(lambda x: not x.vat_discriminated):
tax_groups = order.order_line.mapped('tax_id.tax_group_id')
tax_groups = order.order_line.mapped("tax_id.tax_group_id")
if not tax_groups:
continue
to_remove_ids = tax_groups.filtered(lambda x: x.l10n_ar_vat_afip_code).ids
tax_group_vals = order.tax_totals['subtotals'][0]['tax_groups']
tax_group_vals = order.tax_totals["subtotals"][0]["tax_groups"]
# TODO revisar si es discriminar / no discrminar
updated_tax_group_vals = list(filter(lambda x: x.get('id') not in to_remove_ids, tax_group_vals))
order.tax_totals['subtotals'][0]['tax_groups'] = updated_tax_group_vals
updated_tax_group_vals = list(filter(lambda x: x.get("id") not in to_remove_ids, tax_group_vals))
order.tax_totals["subtotals"][0]["tax_groups"] = updated_tax_group_vals

def _get_name_sale_report(self, report_xml_id):
""" Method similar to the '_get_name_invoice_report' of l10n_latam_invoice_document
"""Method similar to the '_get_name_invoice_report' of l10n_latam_invoice_document
Basically it allows different localizations to define it's own report
This method should actually go in a sale_ux module that later can be extended by different localizations
Another option would be to use report_substitute module and setup a subsitution with a domain
"""
self.ensure_one()
if self.company_id.country_id.code == 'AR':
return 'l10n_ar_sale.report_saleorder_document'
if self.company_id.country_id.code == "AR":
return "l10n_ar_sale.report_saleorder_document"
return report_xml_id

def _create_invoices(self, grouped=False, final=False, date=None):
""" Por alguna razon cuando voy a crear la factura a traves de una devolucion, no me esta permitiendo crearla
"""Por alguna razon cuando voy a crear la factura a traves de una devolucion, no me esta permitiendo crearla
y validarla porque resulta el campo tipo de documento esta quedando vacio. Este campo se llena y computa
automaticamente al generar al modificar el diaro de una factura.
Si hacemos la prueba funcional desde la interfaz funciona, si intento importar la factura con el importador de
Odoo funciona, pero si la voy a crear desde la devolucion inventario no se rellena dicho campo.
Para solventar decimos si tenemos facturas que usan documentos y que no tienen un tipo de documento, intentamos
computarlo y asignarlo, esto aplica para cuando generamos una factura desde una orden de venta o suscripcion """
computarlo y asignarlo, esto aplica para cuando generamos una factura desde una orden de venta o suscripcion"""
invoices = super()._create_invoices(grouped=grouped, final=final, date=date)

# Intentamos Completar el dato tipo de documento si no seteado
# Intentamos Completar el dato tipo de documento si no seteado
to_fix = invoices.filtered(lambda x: x.l10n_latam_use_documents and not x.l10n_latam_document_type_id)
to_fix._compute_l10n_latam_available_document_types()
return invoices

def is_module_installed(self, module):
module_installed = self.env['ir.module.module'].search([
('name', '=', module),
('state', '=', 'installed'),
])
module_installed = self.env["ir.module.module"].search(
[
("name", "=", module),
("state", "=", "installed"),
]
)
return True if module_installed else False
113 changes: 53 additions & 60 deletions l10n_ar_sale/models/sale_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,95 +2,83 @@
# For copyright and license notices, see __manifest__.py file in module root
# directory
##############################################################################
from odoo import models, fields, api, _
from odoo.exceptions import UserError
import logging

from odoo import _, api, fields, models
from odoo.exceptions import UserError

_logger = logging.getLogger(__name__)


class SaleOrderLine(models.Model):
_inherit = "sale.order.line"

report_price_unit = fields.Float(
compute='_compute_report_prices_and_taxes',
digits='Report Product Price',
compute="_compute_report_prices_and_taxes",
digits="Report Product Price",
)
price_unit_with_tax = fields.Float(
compute='_compute_report_prices_and_taxes',
digits='Product Price',
)
report_price_subtotal = fields.Monetary(
compute='_compute_report_prices_and_taxes'
compute="_compute_report_prices_and_taxes",
digits="Product Price",
)
report_price_subtotal = fields.Monetary(compute="_compute_report_prices_and_taxes")
report_price_net = fields.Float(
compute='_compute_report_prices_and_taxes',
digits='Report Product Price',
compute="_compute_report_prices_and_taxes",
digits="Report Product Price",
)
report_tax_id = fields.One2many(
compute="_compute_report_prices_and_taxes",
comodel_name='account.tax',
comodel_name="account.tax",
)

vat_tax_id = fields.Many2one(
'account.tax',
compute='_compute_vat_tax_id',
)
report_price_reduce = fields.Monetary(
compute='_compute_report_price_reduce'
"account.tax",
compute="_compute_vat_tax_id",
)
report_price_reduce = fields.Monetary(compute="_compute_report_price_reduce")

@api.depends('price_unit', 'price_subtotal', 'order_id.vat_discriminated')
@api.depends("price_unit", "price_subtotal", "order_id.vat_discriminated")
def _compute_report_price_reduce(self):
for line in self:
price_type = line.price_subtotal \
if line.order_id.vat_discriminated else line.price_total
line.report_price_reduce = price_type / line.product_uom_qty \
if line.product_uom_qty else 0.0
price_type = line.price_subtotal if line.order_id.vat_discriminated else line.price_total
line.report_price_reduce = price_type / line.product_uom_qty if line.product_uom_qty else 0.0

@api.depends(
'tax_id.tax_group_id.l10n_ar_vat_afip_code',
"tax_id.tax_group_id.l10n_ar_vat_afip_code",
)
def _compute_vat_tax_id(self):
for rec in self:
vat_tax_id = rec.tax_id.filtered(lambda x: x.tax_group_id.l10n_ar_vat_afip_code)
if len(vat_tax_id) > 1:
raise UserError(_('Only one vat tax allowed per line'))
raise UserError(_("Only one vat tax allowed per line"))
rec.vat_tax_id = vat_tax_id

@api.depends(
'price_unit',
'price_subtotal',
'order_id.vat_discriminated'
)
@api.depends("price_unit", "price_subtotal", "order_id.vat_discriminated")
def _compute_report_prices_and_taxes(self):
for line in self:
order = line.order_id
taxes_included = not order.vat_discriminated
price_unit = line.tax_id.with_context(round=False).compute_all(
line.price_unit, order.currency_id, 1.0, line.product_id,
order.partner_shipping_id)
line.price_unit, order.currency_id, 1.0, line.product_id, order.partner_shipping_id
)
if not taxes_included:
report_price_unit = price_unit['total_excluded']
report_price_unit = price_unit["total_excluded"]
report_price_subtotal = line.price_subtotal
not_included_taxes = line.tax_id
report_price_net = report_price_unit * (
1 - (line.discount or 0.0) / 100.0)
report_price_net = report_price_unit * (1 - (line.discount or 0.0) / 100.0)
else:
included_taxes = line.tax_id.filtered(lambda x: x.tax_group_id.l10n_ar_vat_afip_code)
not_included_taxes = (
line.tax_id - included_taxes)
report_price_unit = included_taxes.with_context(
round=False).compute_all(
line.price_unit, order.currency_id, 1.0, line.product_id,
order.partner_shipping_id)['total_included']
report_price_net = report_price_unit * (
1 - (line.discount or 0.0) / 100.0)
not_included_taxes = line.tax_id - included_taxes
report_price_unit = included_taxes.with_context(round=False).compute_all(
line.price_unit, order.currency_id, 1.0, line.product_id, order.partner_shipping_id
)["total_included"]
report_price_net = report_price_unit * (1 - (line.discount or 0.0) / 100.0)
price = line.price_unit * (1 - (line.discount or 0.0) / 100.0)
report_price_subtotal = included_taxes.compute_all(
price, order.currency_id, line.product_uom_qty,
line.product_id, order.partner_shipping_id)['total_included']
price, order.currency_id, line.product_uom_qty, line.product_id, order.partner_shipping_id
)["total_included"]

line.price_unit_with_tax = price_unit['total_included']
line.price_unit_with_tax = price_unit["total_included"]
line.report_price_subtotal = report_price_subtotal
line.report_price_unit = report_price_unit
line.report_price_net = report_price_net
Expand All @@ -109,32 +97,37 @@ def check_vat_tax(self):
"""
# por ahora, para no romper el install de sale_timesheet lo
# desactivamos en la instalacion
if self.env.context.get('install_mode'):
if self.env.context.get("install_mode"):
return True
for rec in self.filtered(
lambda x: not x.display_type and
x.company_id.country_id == self.env.ref('base.ar') and
x.company_id.l10n_ar_company_requires_vat):
vat_taxes = rec.tax_id.filtered(
lambda x: x.tax_group_id.l10n_ar_vat_afip_code)
lambda x: not x.display_type
and x.company_id.country_id == self.env.ref("base.ar")
and x.company_id.l10n_ar_company_requires_vat
):
vat_taxes = rec.tax_id.filtered(lambda x: x.tax_group_id.l10n_ar_vat_afip_code)
if len(vat_taxes) != 1:
raise UserError(_(
'Debe haber un único impuesto del grupo de impuestos "IVA" por línea, agréguelo a "%s". '
'En caso de tenerlo, revise la configuración del impuesto, en opciones avanzadas, '
'en el campo correspondiente "Grupo de Impuestos".',
rec.product_id.name))
raise UserError(
_(
'Debe haber un único impuesto del grupo de impuestos "IVA" por línea, agréguelo a "%s". '
"En caso de tenerlo, revise la configuración del impuesto, en opciones avanzadas, "
'en el campo correspondiente "Grupo de Impuestos".',
rec.product_id.name,
)
)

def write(self, vals):
res = super(SaleOrderLine, self).write(vals)
# for performance we only check if tax or company is on vals
if 'tax_id' in vals or 'company_id' in vals:
if "tax_id" in vals or "company_id" in vals:
self.check_vat_tax()
return res

def _compute_tax_id(self):
""" Agregado de taxes de modulo l10n_ar_tax segun fiscal position """
"""Agregado de taxes de modulo l10n_ar_tax segun fiscal position"""
super()._compute_tax_id()

for rec in self.filtered('order_id.fiscal_position_id.l10n_ar_tax_ids'):
for rec in self.filtered("order_id.fiscal_position_id.l10n_ar_tax_ids"):
date = rec.order_id.date_order
rec.tax_id += rec.order_id.fiscal_position_id._l10n_ar_add_taxes(rec.order_partner_id, rec.company_id, date, 'perception')
rec.tax_id += rec.order_id.fiscal_position_id._l10n_ar_add_taxes(
rec.order_partner_id, rec.company_id, date, "perception"
)
8 changes: 4 additions & 4 deletions l10n_ar_sale/wizards/res_config_settings.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from odoo import models, fields
from odoo import fields, models


class ResConfigSettings(models.TransientModel):
_inherit = 'res.config.settings'
_inherit = "res.config.settings"

group_price_unit_with_tax = fields.Boolean(
"Unit Price w/ Taxes",
implied_group='l10n_ar_sale.sale_price_unit_with_tax',
implied_group="l10n_ar_sale.sale_price_unit_with_tax",
)
group_delivery_date = fields.Boolean(
"Show Delivery Date in Quotations report and online budget",
implied_group='l10n_ar_sale.group_delivery_date_on_report_online'
implied_group="l10n_ar_sale.group_delivery_date_on_report_online",
)
Loading

0 comments on commit 99b1a15

Please sign in to comment.