diff --git a/cdfi_invoice/.gitignore b/cdfi_invoice/.gitignore new file mode 100644 index 0000000..d996887 --- /dev/null +++ b/cdfi_invoice/.gitignore @@ -0,0 +1,53 @@ +# Archivos de caché de Python +_pycache_/ +*.pyc +*.pyo +*.pyd + +# Configuración de editores de código +.vscode/ +.idea/ +*.sublime-workspace +*.swp + +# Archivos de logs +logs/ +*.log + +# Archivos de pruebas y datos temporales +tests/ +*.coverage +*.pytest_cache/ + +# Archivos de compilación +*.egg-info/ +*.dist-info/ +*.tox/ +build/ +dist/ + +# Base de datos SQLite (si se usa para pruebas) +*.db + +# Carpetas generadas por Odoo +*.pot +*.po~ +*.mo +*.zip +*.tar.gz +*.bak +*.tmp + +# Archivos de configuración de Odoo que pueden cambiar en cada entorno +config/ +odoo.conf + +# Archivos específicos de Docker y Virtual Environments +.env +venv/ +.envrc +.dockerignore + +# Archivos de dependencias locales +node_modules/ +bower_components/ \ No newline at end of file diff --git a/cdfi_invoice/models/sale.py b/cdfi_invoice/models/sale.py index 9acc409..f989cf3 100644 --- a/cdfi_invoice/models/sale.py +++ b/cdfi_invoice/models/sale.py @@ -1,85 +1,115 @@ # -*- coding: utf-8 -*- from odoo import api, fields, models, _ -#import odoo.addons.decimal_precision as dp -from . import amount_to_text_es_MX + +# import odoo.addons.decimal_precision as dp +from . import amount_to_text_es_MX import pytz import logging + _logger = logging.getLogger(__name__) + class SaleOrder(models.Model): - _inherit = 'sale.order' + _inherit = "sale.order" - forma_pago_id = fields.Many2one('catalogo.forma.pago', string='Forma de pago') - #num_cta_pago = fields.Char(string='Núm. Cta. Pago') + forma_pago_id = fields.Many2one("catalogo.forma.pago", string="Forma de pago") + # num_cta_pago = fields.Char(string='Núm. Cta. Pago') methodo_pago = fields.Selection( - selection=[('PUE', 'Pago en una sola exhibición'), - ('PPD', 'Pago en parcialidades o diferido'),], - string='Método de pago', + selection=[ + ("PUE", "Pago en una sola exhibición"), + ("PPD", "Pago en parcialidades o diferido"), + ], + string="Método de pago", ) - uso_cfdi_id = fields.Many2one('catalogo.uso.cfdi', string='Uso CFDI (cliente)') - fecha_corregida = fields.Datetime(string='Fecha Cotizacion', compute='_get_fecha_corregida') - company_cfdi = fields.Boolean(related="company_id.company_cfdi",store=True) + uso_cfdi_id = fields.Many2one("catalogo.uso.cfdi", string="Uso CFDI (cliente)") + fecha_corregida = fields.Datetime( + string="Fecha Cotizacion", compute="_get_fecha_corregida" + ) + company_cfdi = fields.Boolean(related="company_id.company_cfdi", store=True) - @api.onchange('partner_id') + @api.onchange("partner_id") def _get_uso_cfdi(self): if self.partner_id: - values = { - 'uso_cfdi_id': self.partner_id.uso_cfdi_id.id - } + values = {"uso_cfdi_id": self.partner_id.uso_cfdi_id.id} self.update(values) - @api.onchange('payment_term_id') + @api.onchange("payment_term_id") def _get_metodo_pago(self): if self.payment_term_id: - if self.payment_term_id.methodo_pago == 'PPD': + if self.payment_term_id.methodo_pago == "PPD": values = { - 'methodo_pago': self.payment_term_id.methodo_pago, - 'forma_pago_id': self.env['catalogo.forma.pago'].sudo().search([('code','=','99')]) - } + "methodo_pago": self.payment_term_id.methodo_pago, + "forma_pago_id": self.env["catalogo.forma.pago"] + .sudo() + .search([("code", "=", "99")]), + } else: values = { - 'methodo_pago': self.payment_term_id.methodo_pago, - 'forma_pago_id': False - } - else: - values = { - 'methodo_pago': False, - 'forma_pago_id': False + "methodo_pago": self.payment_term_id.methodo_pago, + "forma_pago_id": False, } + else: + values = {"methodo_pago": False, "forma_pago_id": False} self.update(values) - @api.depends('amount_total', 'currency_id') + @api.depends("amount_total", "currency_id") def _get_amount_to_text(self): for record in self: - record.amount_to_text = amount_to_text_es_MX.get_amount_to_text(record, record.amount_total, 'es_cheque', record.currency_id.name) - + record.amount_to_text = amount_to_text_es_MX.get_amount_to_text( + record, record.amount_total, "es_cheque", record.currency_id.name + ) + @api.model def _get_amount_2_text(self, amount_total): - return amount_to_text_es_MX.get_amount_to_text(self, amount_total, 'es_cheque', self.currency_id.name) - - + return amount_to_text_es_MX.get_amount_to_text( + self, amount_total, "es_cheque", self.currency_id.name + ) + def _prepare_invoice(self): invoice_vals = super(SaleOrder, self)._prepare_invoice() - invoice_vals.update({'forma_pago_id': self.forma_pago_id.id, - 'methodo_pago': self.methodo_pago, - 'uso_cfdi_id': self.uso_cfdi_id.id, - 'tipo_comprobante': 'I' - }) + invoice_vals.update( + { + "forma_pago_id": self.forma_pago_id.id, + "methodo_pago": self.methodo_pago, + "uso_cfdi_id": self.uso_cfdi_id.id, + "tipo_comprobante": "I", + } + ) return invoice_vals - def _get_fecha_corregida(self): for sale in self: - if sale.date_order: - #corregir hora - timezone = sale._context.get('tz') - if not timezone: - timezone = sale.env.user.partner_id.tz or 'America/Mexico_City' - #timezone = tools.ustr(timezone).encode('utf-8') - - local = pytz.timezone(timezone) - naive_from = sale.date_order - local_dt_from = naive_from.replace(tzinfo=pytz.UTC).astimezone(local) - sale.fecha_corregida = local_dt_from.strftime ("%Y-%m-%d %H:%M:%S") - #_logger.info('fecha ... %s', sale.fecha_corregida) + if sale.date_order: + # corregir hora + timezone = sale._context.get("tz") + if not timezone: + timezone = sale.env.user.partner_id.tz or "America/Mexico_City" + # timezone = tools.ustr(timezone).encode('utf-8') + + local = pytz.timezone(timezone) + naive_from = sale.date_order + local_dt_from = naive_from.replace(tzinfo=pytz.UTC).astimezone(local) + sale.fecha_corregida = local_dt_from.strftime("%Y-%m-%d %H:%M:%S") + # _logger.info('fecha ... %s', sale.fecha_corregida) + + @api.model_create_multi + def create(self, vals_list): + orders = super().create(vals_list) + + for order in orders: + + if order.partner_id and not order.uso_cfdi_id: + order.uso_cfdi_id = order.partner_id.uso_cfdi_id.id + + if order.payment_term_id: + order.methodo_pago = order.payment_term_id.methodo_pago + + if order.payment_term_id.methodo_pago == "PPD": + order.forma_pago_id = ( + self.env["catalogo.forma.pago"] + .sudo() + .search([("code", "=", "99")], limit=1) + ) + + return orders diff --git a/cdfi_invoice/views/account_invoice_view.xml b/cdfi_invoice/views/account_invoice_view.xml index c039e2c..f6d22eb 100644 --- a/cdfi_invoice/views/account_invoice_view.xml +++ b/cdfi_invoice/views/account_invoice_view.xml @@ -1,102 +1,167 @@ - - + + account.move.inherit.tree account.move - - - - - + + + + + + - - account.move.inherit.form - account.move - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + account.move.inherit.form + account.move + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - + + + + + + + + + + + + + + + + + + - + + + + - + Desbloquear CFDI - - + + code action = records.liberar_cfdi() - + mymodule.message.wizard.form mymodule.message.wizard - +
- +