Skip to content

Instantly share code, notes, and snippets.

@celm1990
Created July 5, 2023 17:46
Show Gist options
  • Select an option

  • Save celm1990/2dfcc33e72fcc7081b07c2ebaf2fbe37 to your computer and use it in GitHub Desktop.

Select an option

Save celm1990/2dfcc33e72fcc7081b07c2ebaf2fbe37 to your computer and use it in GitHub Desktop.
l10n_latam_pos
from odoo import fields, models
class PosConfig(models.Model):
_inherit = "pos.config"
l10n_latam_document_type_ids = fields.Many2many(
"l10n_latam.document.type",
"pos_config_latam_document_type_rel",
"pos_config_id",
"document_type_id",
string="Tipos de Documentos disponibles",
)
l10n_latam_document_type_id = fields.Many2one(
"l10n_latam.document.type",
string="Documento por defecto",
)
from odoo import api, fields, models
class PosOrder(models.Model):
_inherit = "pos.order"
country_code = fields.Char(
related="company_id.account_fiscal_country_id.code", readonly=True
)
l10n_latam_document_type_id = fields.Many2one(
"l10n_latam.document.type",
string="Tipo de Documento",
readonly=True,
auto_join=True,
index="btree_not_null",
)
@api.model
def _order_fields(self, ui_order):
vals = super()._order_fields(ui_order)
vals["l10n_latam_document_type_id"] = ui_order.get(
"l10n_latam_document_type_id"
)
return vals
def _export_for_ui(self, order):
vals = super()._export_for_ui(order)
vals["l10n_latam_document_type_id"] = order.l10n_latam_document_type_id.id
return vals
from odoo import models
class PosSession(models.Model):
_inherit = "pos.session"
def _pos_data_process(self, loaded_data):
res = super()._pos_data_process(loaded_data)
if self.config_id.l10n_latam_document_type_ids:
loaded_data["l10n_latam_document_type_by_id"] = {
latam_document_type["id"]: latam_document_type
for latam_document_type in loaded_data["l10n_latam.document.type"]
}
return res
def _pos_ui_models_to_load(self):
result = super()._pos_ui_models_to_load()
models = ["l10n_latam.identification.type"]
if self.config_id.l10n_latam_document_type_ids:
models.append("l10n_latam.document.type")
result.extend([a for a in models if a not in result])
return result
def _loader_params_l10n_latam_document_type(self):
if self.config_id.l10n_latam_document_type_ids:
domain = [("id", "in", self.config_id.l10n_latam_document_type_ids.ids)]
return {
"search_params": {
"domain": domain,
"fields": ["id", "name", "code", "internal_type"],
"load": False,
}
}
def _get_pos_ui_l10n_latam_document_type(self, params):
latam_document_types = self.env["l10n_latam.document.type"].search_read(
**params["search_params"]
)
return latam_document_types
def _loader_params_l10n_latam_identification_type(self):
return {
"search_params": {
"domain": [("country_id", "=", self.company_id.country_id.id)],
"fields": ["id", "name", "country_id", "is_vat"],
"load": False,
}
}
def _get_pos_ui_l10n_latam_identification_type(self, params):
latam_identification_types = self.env[
"l10n_latam.identification.type"
].search_read(**params["search_params"])
return latam_identification_types
def _loader_params_res_partner(self):
result = super()._loader_params_res_partner()
result["search_params"]["fields"].append("l10n_latam_identification_type_id")
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment