Skip to content

Instantly share code, notes, and snippets.

@akhdaniel
Last active February 3, 2021 09:03
Show Gist options
  • Save akhdaniel/2ff084b1f89143f08ad2a041b253676f to your computer and use it in GitHub Desktop.
Save akhdaniel/2ff084b1f89143f08ad2a041b253676f to your computer and use it in GitHub Desktop.
Template Stored Procedure Odoo
from odoo import models, fields, api

import logging
_logger = logging.getLogger(__name__)



class account_move(models.Model):
    _name = 'account.move'
    _inherit = 'account.move'

    @api.model_cr
    def init(self):
        _logger.info("creating vit_turbo_validate_account_move function...")
        self.env.cr.execute("""CREATE OR REPLACE FUNCTION public.vit_turbo_validate_account_move(
                v_am_id integer, v_company_id integer)
                RETURNS void
                LANGUAGE 'plpgsql'

                COST 100
                VOLATILE 

            AS $BODY$
            DECLARE
                v_sequence record;
            BEGIN
                -- browse account move
                SELECT * from account_move where id = v_am_id into v_am;

            END;
            $BODY$;

        """)


    def turbo_action_post(self):
        company_id=self.env['res.company']._company_default_get('account.invoice').id
        self.env.cr.execute("select vit_turbo_validate_account_move(%s, %s)" % (self.id,company_id) )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment