Esempio n. 1
0
 def _auto_init(self):
     # Skip the computation of the field `l10n_latam_document_type_id` at the module installation
     # Without this, at the module installation,
     # it would call `_compute_l10n_latam_document_type` on all existing records
     # which can take quite a while if you already have a lot of moves. It can even fail with a MemoryError.
     # In addition, it sets `_compute_l10n_latam_document_type = False` on all records
     # because this field depends on the many2many `l10n_latam_available_document_type_ids`,
     # which relies on having records for the model `l10n_latam.document.type`
     # which only happens once the according localization module is loaded.
     # The localization module is loaded afterwards, because the localization module depends on this module,
     # (e.g. `l10n_cl` depends on `l10n_latam_invoice_document`, and therefore `l10n_cl` is loaded after)
     # and therefore there are no records for the model `l10n_latam.document.type` at the time this fields
     # gets computed on installation. Hence, all records' `_compute_l10n_latam_document_type` are set to `False`.
     # In addition, multiple localization module depends on this module (e.g. `l10n_cl`, `l10n_ar`)
     # So, imagine `l10n_cl` gets installed first, and then `l10n_ar` is installed next,
     # if `l10n_latam_document_type_id` needed to be computed on install,
     # the install of `l10n_cl` would call the compute method,
     # because `l10n_latam_invoice_document` would be installed at the same time,
     # but then `l10n_ar` would miss it, because `l10n_latam_invoice_document` would already be installed.
     # Besides, this field is computed only for drafts invoices, as stated in the compute method:
     # `for rec in self.filtered(lambda x: x.state == 'draft'):`
     # So, if we want this field to be computed on install, it must be done only on draft invoices, and only once
     # the localization modules are loaded.
     # It should be done in a dedicated post init hook,
     # filtering correctly the invoices for which it must be computed.
     # Though I don't think this is needed.
     # In practical, it's very rare to already have invoices (draft, in addition)
     # for a Chilian or Argentian company (`res.company`) before installing `l10n_cl` or `l10n_ar`.
     if not column_exists(self.env.cr, "account_move",
                          "l10n_latam_document_type_id"):
         create_column(self.env.cr, "account_move",
                       "l10n_latam_document_type_id", "int4")
     return super()._auto_init()
Esempio n. 2
0
 def _auto_init(self):
     # Skip the computation of the field `l10n_latam_document_type_id` at the module installation
     # See `_auto_init` in `l10n_latam_invoice_document/models/account_move.py` for more information
     if not column_exists(self.env.cr, "account_move_line",
                          "l10n_latam_document_type_id"):
         create_column(self.env.cr, "account_move_line",
                       "l10n_latam_document_type_id", "int4")
     return super()._auto_init()
Esempio n. 3
0
 def _auto_init(self):
     """ Create column for `preferred_payment_method_id` to avoid having it
     computed by the ORM on installation. Since `property_payment_method_id` is
     introduced in this module, there is no need for UPDATE
     """
     if not column_exists(self.env.cr, "account_move",
                          "preferred_payment_method_id"):
         create_column(self.env.cr, "account_move",
                       "preferred_payment_method_id", "int4")
     return super()._auto_init()
Esempio n. 4
0
    def _auto_init(self):
        """
        Create related field here, too slow
        when computing it afterwards through _compute_related.

        Since group_id.sale_id is created in this module,
        no need for an UPDATE statement.
        """
        if not column_exists(self.env.cr, 'stock_picking', 'sale_id'):
            create_column(self.env.cr, 'stock_picking', 'sale_id', 'int4')
        return super()._auto_init()
Esempio n. 5
0
 def _auto_init(self):
     """
     Create column to stop ORM from computing it himself (too slow)
     """
     if not column_exists(self.env.cr, 'sale_order_line', 'is_service'):
         create_column(self.env.cr, 'sale_order_line', 'is_service', 'bool')
         self.env.cr.execute("""
             UPDATE sale_order_line line
             SET is_service = (pt.type = 'service')
             FROM product_product pp
             LEFT JOIN product_template pt ON pt.id = pp.product_tmpl_id
             WHERE pp.id = line.product_id
         """)
     return super()._auto_init()