0
votes

In my country every electronic invoice is required by law to include a field called "Control Code".

The control code is computed by a series of calculations and algorithms using the invoice date, the invoice number and a few custom fields.

Right now I already have a Python script that generates the control code, but it is a stand alone script, which requires you to manually insert the variables.

I really would like to use this script inside an OpenERP module. I would like the script to:

  1. Validate an Invoice (with all the required fields)

  2. Populate the control code field on the invoice with the result of the Python script.

  3. Ensure the invoice is validated and the Field Control Code is stored in the invoice.

1
Have you written an OpenERP module before? What have you tried? What works, and what doesn't work?Wayne Werner

1 Answers

1
votes

Use function's field to solve this problem.

_inherit = 'account.invoice'

def generate_control_code(self, cr, uid, ids, field_name, arg, context=None)
# ids - Invoice ids
# filed_name - Name of the field. In this case 'control_code'
# Return result format {id'_1_': value'_1_', id'_2_': value'_2_',...}.
....
....
....
    return result


_columns = {

    'control_code': fields.function(generate_control_code, type='char', string='Control Code', method=True),

}

For more details please check out this document link http://www.theopensourcerer.com/2012/12/how-to-install-openerp-7-0-on-ubuntu-12-04-lts/