class ResPartner(models.Model): _inherit = 'res.partner' _columns = { 'name': old_fields.char('Name', required=True, select=True, track_visibility='onchange'), 'phone': old_fields.char('Phone', track_visibility='onchange'), }
class WebsiteProposalTemplate(models.Model): _name = "website_proposal.template" _description = "Proposal Template" _columns = { 'name': fields.char('Proposal Template', required=True), 'head': fields.text('Html head'), 'page_header': fields.html('Page header'), 'website_description': fields.html('Description'), 'page_footer': fields.html('Page footer'), 'res_model': fields.char( 'Model', help="The database object this template will be applied to"), } def open_template(self): return { 'type': 'ir.actions.act_url', 'target': 'self', 'url': '/website_proposal/template/%d' % ids[0] } def create_proposal(self, template_id, res_id): if not template_id: return False if isinstance(template_id, list): template_id = template_id[0] template = self.env['website_proposal.template'].browse(template_id) vals = { 'template_id': template_id, 'head': template.head, 'page_header': template.page_header, 'website_description': template.website_description, 'page_footer': template.page_footer, 'res_id': res_id, 'res_model': context.get('force_res_model') or template.res_model, } proposal_id = self.env['website_proposal.proposal'].create( vals, context) return proposal_id
class res_partner(models.Model): _inherit = "res.partner" _columns = { # RUC: Registro Unico del Contribuyente (Panama) 'ruc': fields.char('RUC', size=45, required=True), # DV: Digito verificador 'dv': fields.char('DV', size=2, required=True), # TIPO_PERSONA # 1=NATURAL # 2=JURIDICO # 3=OTROS # 4=EXTRANJERO 'tipo_persona': fields.selection([('1','NATURAL'),('2','JURIDICO'),('3','OTROS'),('4','EXTRANJERO')],'Tipo Persona',required=True), # Concepto Varios a Uno #'concepto' : fields.many2one('anexos.conceptos.pa', 'concepto','Anexo Concepto', store=True, readonly=False) #'concepto' : fields.many2many('anexos.conceptos.pa','res_partner_anexos_conceptos_pa_rel','partner_id', 'concepto','Concepto de Anexo', store=True, readonly=False) }
class Lead(models.Model): _inherit = 'crm.lead' currencyy_id = fields.Boolean(string="Dolar") show_ccu = fields.Boolean(string="show ccu") ccurrency_id = fields.char(string="ingreso en dolares")
class citasmv(models.Model): _name = 'citasmv.citasmv' name = fields.char(string="Autor:", size=100, required=True), fecha = fields.date(string="Fecha de visualizaciòn:", required=True), description = fields.text(string="Descripciòn de la cita:", size=256, required=True), orden = fields.integer(string="Orden de visualizaciòn:", required=True)
class res_partner_working_time(models.Model): _name = "res.partner.working.time" _columns = { 'partner_id': fields.many2one( 'res.partner', 'Partner', ondelete='cascade', select=True, domain=['|', ('is_company', '=', True), ('parent_id', '=', False)]), 'days': fields.char('Days'), 'morning': fields.char('Morning'), 'afternoon': fields.char('Afternoon'), }
class ribons(models.Model): _inherits = 'res.product' _name = 'police.ribons' name = fields.Char('Ribon', required=True) alias = fields.char('ribon', required=True) serving_date = fields.Date('Introduced From') service_age = fields.Integer('Service Age') Posting = Fields.Char('Posting') is_medal = fields.Bool('Is a Medal') position_serial = fields.Float('Priority') image = fields.Binary('Image', help='Select image here') medal_image = fields.Binary('Image', help='Select image here')
class account_voucher_line(osv.osv): _inherit= 'account.voucher.line' _columns={ 'event_date': fields.date('Date Of Service'), 'patient_id': fields.many2one('patient', 'Patient/Client',), 'reference': fields.char('Reference', size=64, select=1), 'project_name_id':fields.many2one('project','Project'), } def default_get(self, cr, user, fields_list, context=None): vals = super(account_voucher_line, self).default_get(cr, user, fields_list,context=context) vals.update({ 'account_id':'', 'type':'' }) return vals
class HrChildren(model.Model): """Class to add object of childrens to employee """ _name = "hr.children" _order = 'name' _columns = { 'name': fields.char('Name', size=64, required=True), 'date_of_birth': fields.date('Date of birth'), 'schooling': fields.selection([('elementary', 'Elementary'), ('high_school', 'High School'), ('preparatory', 'Preparatory'), ('university', 'University')], 'Schooling'), 'employee_id': fields.many2one('hr.employee', 'Employee') }
class kml_map(osv.osv): _name = "kml.map" # def update_file(self , cr ,uid ,ids , context = None): # a=get_dropbox_file() # print "a.........", a def update_file1(self, cr, uid, ids, context=None): # smb = smbclient.SambaClient(server="192.168.1.50", share="root", # username="******", password="******", domain="baz") # f = smb.open('/opt/openerp-7.0/addons_iu/bista_iugroup/mymap3.html') # data = f.read() # print "data..........",data # f.close() # start_server(port, password) # fh = None try: fh = "/home/openerp/workspace/openerp/openerp-7.0/openerp/addons/bista_iugroup/mymap3.html" file_contents = fh.read() finally: if fh is not None: fh.close() file_name_remote = "/opt/openerp-7.0/addons_iu/bista_iugroup/mymap3.html" write_file_remote(host, port, password, file_name_remote, file_contents) def kml_map(self, cr, uid, ids, context=None): # import simplekml # kml = simplekml.Kml() # kml.newpoint(name="Kirstenbosch", coords=[(18.432314,-33.988862)]) # kml.save("botanicalgarden.kml") keyword = self.browse( cr, uid, ids[0], ).name print "keyword..........", keyword #gmaps = GoogleMaps('AIzaSyBoZc-_7KabQcUo9nHTL-xCED6k2_Gj9BM') customer_address = '' customer_obj = self.pool.get('res.partner') customer_ids = customer_obj.search( cr, uid, ['|', ('city', 'ilike', keyword), ('zip', 'ilike', keyword)]) # query = "select id from res_partner where upper(city) = %s or zip = %s"%( str(keyword).upper() , str(keyword)) # cr.execute(query ) # customer_ids = map(lambda x: x[0], cr.fetchall()) print "customer_ids.........", customer_ids # results1 = Geocoder.geocode(keyword) # cord1 = results1[0].coordinates # print "cord1........",cord1 # if len(cord1) > 1 and cord1[0] and cord1[1]: # lat1 = cord1[0] # lon1 = cord1[1] # mymap = pygmaps.maps(lat1, lon1, 7) # kml_doc = create_document('Customer\'s', 'Nearby Area') print "kml_doc........", kml_doc document = kml_doc.documentElement.getElementsByTagName('Document')[0] style_doc = create_style('Wake', \ 'http://maps.google.com/mapfiles/kml/paddle/red-blank.png') document.appendChild(style_doc.documentElement) style_doc = create_style('Durham', \ 'http://maps.google.com/mapfiles/kml/paddle/blu-blank.png') document.appendChild(style_doc.documentElement) style_doc = create_style('Orange', \ 'http://maps.google.com/mapfiles/kml/paddle/wht-blank.png') document.appendChild(style_doc.documentElement) # for address in read_addresses('/home/openerp/Documents/address.csv'): # print "address.........",address # address['address_string'] = \ # '%(address)s, %(city)s, %(state)s %(zip)s' % address # print "address......",address for customer_id in customer_ids: customer = customer_obj.browse(cr, uid, customer_id) #address={'city': 'Apex', 'name': 'Apex - Williams Street', 'zip': '27539', 'country': 'Wake', 'phone': '919-362-6796', 'state': 'NC', 'address': '1581 East Williams Street'} customer_address = '' title = '' if customer.name: title += customer.name if customer.middle_name: title += ' ' + customer.middle_name if customer.last_name: title += ' ' + customer.last_name #print "title........",title address = {} address['name'] = title if customer.street: customer_address += customer.street address['address'] = customer.street if customer.city: customer_address += ' ' + customer.city address['city'] = customer.city if customer.state_id: customer_address += ' ' + customer.state_id.name address['state'] = customer.state_id.name if customer.country_id: customer_address += ' ' + customer.country_id.name address['country'] = customer.country_id.name if customer.zip: customer_address += ' ' + customer.zip address['zip'] = customer.zip if customer.phone: address['phone'] = customer.phone if customer.email: address['email'] = customer.email address['county'] = 1 print "address......", address #print "customer_address........address.",customer_address,address # try: # lat, lon = gmaps.address_to_latlng('United states') # except googlemaps.GoogleMapsError, e: # print "Oh, no! Couldn't geocode", addr # print e results = Geocoder.geocode(customer_address) cord = results[0].coordinates print "cord........", cord if len(cord) > 1 and cord[0] and cord[1]: address['latitude'] = cord[0] address['longitude'] = cord[1] #print "lat...lon.......",lat,lon # try: # geocode(address) # except RuntimeError, e: # print >> sys.stderr, e # print >> sys.stderr, "warning: %s skipped" % address['address_string'] # continue placemark = create_placemark(address) document.appendChild(placemark.documentElement) print "Printing....kml........" xml_str = kml_doc.toprettyxml() #indent=" ", encoding='UTF-8' print "xml_str......", xml_str kml_str = remove_xml_tag(kml_doc, xml_str) print "kml_str...........", kml_str # u = urllib.urlopen('http://www.datafilehost.com/get.php?file=4d421236') # raw_data = u.raed(a) # u.close() # file = 'https://www.dropbox.com/meta_dl/eyJzdWJfcGF0aCI6ICIiLCAidGVzdF9saW5rIjogZmFsc2UsICJzZXJ2ZXIiOiAiZGwuZHJvcGJveHVzZXJjb250ZW50LmNvbSIsICJpdGVtX2lkIjogbnVsbCwgImlzX2RpciI6IGZhbHNlLCAidGtleSI6ICJpcThwbzB2Nng3a2RjZGwifQ/AAMG__92aSsxOWK_Eb1FLRxQ0JCYjj-FDIJp9s7jbnLPoA?dl=1' file = 'https://www.dropbox.com/s/yehfc83rxth8i59/new3.kml?dl=1' app_key = 'fmaqmohgdytdkpn' # fh = open(file, "w") # # fh.write(str(a)) # fh.close() # url = 'http://maps.google.com/maps?q=' + 'http://www.datafilehost.com/get.php?file=4d421236' url = 'http://maps.google.com/maps?q=' + file return { 'type': 'ir.actions.act_url', 'url': url, 'nodestroy': True, 'target': 'new' } return True _columns = { 'name': fields.char('City/Zip Code', size=128, select=True), }
class ResPartner(models.Model): _inherit = 'res.partner' edad = fields.Datetime('edad', required=True) fecha_nacimiento = fields.Datetime('fecha_nacimiento', required=True) lf = fields.Char('lf', required=True) field_1 = fields.Many2one('address.code', required=True) field_2 = fields.Integer(required=True) field_3 = fields.Selection(alphabet) field_4 = fields.Many2one('street.code') field_5 = fields.Integer(required=True) field_6 = fields.Selection(alphabet) field_7 = fields.Many2one('street.code') field_8 = fields.Integer(required=True) field_9 = fields.Many2one('address.code') field_10 = fields.Integer() field_11 = fields.Many2one('address.code') field_12 = fields.Integer() street = fields.Char() name = fields.Char(default=lambda self: self.first_name) first_name = fields.Char() middle_name = fields.Char() pater = fields.char() last_name = fields.Char() second_last_name = fields.Char() nit = fields.Char(string='NIT', size=9) dv = fields.Selection([('0', '0'), ('1', '1'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5'), ('6', '6'), ('7', '7'), ('8', '8'), ('9', '9')], string='DV') company_name = fields.Char() company_nature = fields.Selection([ ('S.A.S', 'S.A.S'), ('S.A', 'S.A'), ('LTDA', 'LTDA'), ('PERSONA NATURAL', 'PERSONA NATURAL'), ('EMPRESA UNIPERSONAL', 'EMPRESA UNIPERSONAL'), ('SOCIEDAD COLECTIVA', 'SOCIEDAD COLECTIVA'), ('S. EN C.', 'S. EN C.'), ('S.C.A', 'S.C.A') ]) ciiu = fields.Many2many('ciiu.value', 'ciiu_value_res_partner_rel', 'partner_id', 'ciiu_id', string='CIIU') _sql_constraints = [ ('nit_partner_uniq', 'unique(nit)', 'NIT must be unique!'), ] @api.constrains('nit') def _check_nit_size(self): pattern = "^\+?[0-9]*$" for record in self: if record.nit and re.match(pattern, record.nit) is None: raise ValidationError(_("NIT value must be a numerical.")) @api.onchange('l10n_co_edi_large_taxpayer') def _onchange_gran_contrib(self): if self.l10n_co_edi_large_taxpayer: self.l10n_co_edi_simplified_regimen = False @api.onchange('l10n_co_edi_simplified_regimen') def _onchange_simplified_reg(self): if self.l10n_co_edi_simplified_regimen: self.l10n_co_edi_large_taxpayer = False @api.onchange('field_1', 'field_2', 'field_3', 'field_4', 'field_5', 'field_6', 'field_7', 'field_8', 'field_9', 'field_10', 'field_11', 'field_12') def _onchange_street(self): self.street = "%s %s %s %s %s %s %s %s %s %s %s %s" % ( self.field_1.code if self.field_1 else "", str( self.field_2), str(self.field_3 if self.field_3 else ""), self.field_4.code if self.field_4 else "", str( self.field_5), str(self.field_6 if self.field_6 else ""), self.field_7.code if self.field_7 else "", str(self.field_8), self.field_9.code if self.field_9 else "", str(self.field_10), self.field_11.code if self.field_11 else "", str(self.field_12)) @api.onchange('first_name', 'middle_name', 'last_name', 'second_last_name', 'company_name', 'company_nature') def _onchange_full_name(self): if self.company_type == 'person': self.name = "%s %s %s %s" % ( self.first_name if self.first_name else "", self.middle_name if self.middle_name else "", self.last_name if self.last_name else "", self.second_last_name if self.second_last_name else "") else: self.name = "%s %s" % ( self.company_name if self.company_name else "", self.company_nature if self.company_nature else "") '''from_date=fields.Date(string="Register date")
class olamundo(models.Model): _name = "odoo_olamundo.olamundo" _description = "exemplo olamundo" name = fields.char(string="Ola Mundo")
class WebsiteProposal(models.Model): _name = 'website_proposal.proposal' _rec_name = 'id' def _get_default_company(self): company_id = self.env['res.users']._get_company(context=context) if not company_id: raise UserError(_('Error!'), _('There is no default company for the current user!')) return company_id def _get_res_name(self, name, args): res = {} for r in self.browse(ids): record = self.env[r.res_model].browse(r.res_id) res[r.id] = record.name return res _columns = { 'res_name': fields.function(_get_res_name, string='Name', type='char'), 'access_token': fields.char('Security Token', required=True, copy=False), 'template_id': fields.many2one('website_proposal.template', 'Quote Template', readonly=True), 'head': fields.text('Html head'), 'page_header': fields.text('Page header'), 'website_description': fields.html('Description'), 'page_footer': fields.text('Page footer'), 'res_model': fields.char('Model', readonly=True, help="The database object this is attached to"), 'res_id': fields.integer('Resource ID', readonly=True, help="The record id this is attached to", select=True), 'sign': fields.binary('Singature'), 'sign_date': fields.datetime('Signing Date'), 'signer': fields.binary('Signer'), 'state': fields.selection([ ('draft', 'Draft'), ('rejected', 'Rejected'), ('done', 'Signed'), ]), 'company_id': fields.many2one('res.company', 'Company'), } _defaults = { 'access_token': lambda self, cr, uid, ctx={}: str(uuid.uuid4()), 'company_id': _get_default_company, 'state': 'draft', } def open_proposal(self): return { 'type': 'ir.actions.act_url', 'target': 'self', 'url': '/website_proposal/%s' % (ids[0]) } def edit_proposal(self): return { 'type': 'ir.actions.act_url', 'target': 'self', 'url': '/website_proposal/%s?enable_editor' % (ids[0]) } def create(self, vals): record = self.env[vals.get('res_model']).browse(vals.get('res_id')) mako = mako_template_env.from_string(tools.ustr(vals.get('website_description'))) website_description = mako.render({'record': record}) website_description = website_description.replace('template-only-', '') vals['website_description'] = website_description new_id = super(WebsiteProposal, self).create(vals) return new_id
class account_fiscalyear_close(osv.osv_memory): """ Closes Account Fiscalyear and Generate Opening entries for New Fiscalyear """ _name = "account.fiscalyear.close" _description = "Fiscalyear Close" _columns = { 'fy_id': fields.many2one('account.fiscalyear', 'Fiscal Year to close', required=True, help="Select a Fiscal year to close"), 'fy2_id': fields.many2one('account.fiscalyear', 'New Fiscal Year', required=True), 'journal_id': fields.many2one( 'account.journal', 'Opening Entries Journal', domain="[('type','=','situation')]", required=True, help= 'The best practice here is to use a journal dedicated to contain the opening entries of all fiscal years. Note that you should define it with default debit/credit accounts, of type \'situation\' and with a centralized counterpart.' ), 'period_id': fields.many2one('account.period', 'Opening Entries Period', required=True), 'report_name': fields.char('Name of new entries', required=True, help="Give name of the new entries"), } _defaults = { 'report_name': lambda self, cr, uid, context: _('End of Fiscal Year Entry'), } def data_save(self, cr, uid, ids, context=None): """ This function close account fiscalyear and create entries in new fiscalyear @param cr: the current row, from the database cursor, @param uid: the current user’s ID for security checks, @param ids: List of Account fiscalyear close state’s IDs """ def _reconcile_fy_closing(cr, uid, ids, context=None): """ This private function manually do the reconciliation on the account_move_line given as `ids´, and directly through psql. It's necessary to do it this way because the usual `reconcile()´ function on account.move.line object is really resource greedy (not supposed to work on reconciliation between thousands of records) and it does a lot of different computation that are useless in this particular case. """ # check that the reconcilation concern journal entries from only one company cr.execute( 'select distinct(company_id) from account_move_line where id in %s', (tuple(ids), )) if len(cr.fetchall()) > 1: raise osv.except_osv( _('Warning!'), _('The entries to reconcile should belong to the same company.' )) r_id = self.pool.get('account.move.reconcile').create( cr, uid, { 'type': 'auto', 'opening_reconciliation': True }) cr.execute( 'update account_move_line set reconcile_id = %s where id in %s', ( r_id, tuple(ids), )) # reconcile_ref deptends from reconcile_id but was not recomputed obj_acc_move_line._store_set_values(cr, uid, ids, ['reconcile_ref'], context=context) obj_acc_move_line.invalidate_cache(cr, uid, ['reconcile_id'], ids, context=context) return r_id obj_acc_period = self.pool.get('account.period') obj_acc_fiscalyear = self.pool.get('account.fiscalyear') obj_acc_journal = self.pool.get('account.journal') obj_acc_move = self.pool.get('account.move') obj_acc_move_line = self.pool.get('account.move.line') obj_acc_account = self.pool.get('account.account') obj_acc_journal_period = self.pool.get('account.journal.period') currency_obj = self.pool.get('res.currency') data = self.browse(cr, uid, ids, context=context) if context is None: context = {} fy_id = data[0].fy_id.id cr.execute( "SELECT id FROM account_period WHERE date_stop < (SELECT date_start FROM account_fiscalyear WHERE id = %s)", (str(data[0].fy2_id.id), )) fy_period_set = ','.join(map(lambda id: str(id[0]), cr.fetchall())) cr.execute( "SELECT id FROM account_period WHERE date_start > (SELECT date_stop FROM account_fiscalyear WHERE id = %s)", (str(fy_id), )) fy2_period_set = ','.join(map(lambda id: str(id[0]), cr.fetchall())) if not fy_period_set or not fy2_period_set: raise osv.except_osv( _('User Error!'), _('The periods to generate opening entries cannot be found.')) period = obj_acc_period.browse(cr, uid, data[0].period_id.id, context=context) new_fyear = obj_acc_fiscalyear.browse(cr, uid, data[0].fy2_id.id, context=context) old_fyear = obj_acc_fiscalyear.browse(cr, uid, fy_id, context=context) new_journal = data[0].journal_id.id new_journal = obj_acc_journal.browse(cr, uid, new_journal, context=context) company_id = new_journal.company_id.id if not new_journal.default_credit_account_id or not new_journal.default_debit_account_id: raise osv.except_osv( _('User Error!'), _('The journal must have default credit and debit account.')) if (not new_journal.centralisation) or new_journal.entry_posted: raise osv.except_osv( _('User Error!'), _('The journal must have centralized counterpart without the Skipping draft state option checked.' )) # delete existing move and move lines if any move_ids = obj_acc_move.search(cr, uid, [('journal_id', '=', new_journal.id), ('period_id', '=', period.id)]) if move_ids: move_line_ids = obj_acc_move_line.search( cr, uid, [('move_id', 'in', move_ids)]) obj_acc_move_line._remove_move_reconcile( cr, uid, move_line_ids, opening_reconciliation=True, context=context) obj_acc_move_line.unlink(cr, uid, move_line_ids, context=context) obj_acc_move.unlink(cr, uid, move_ids, context=context) cr.execute("SELECT id FROM account_fiscalyear WHERE date_stop < %s", (str(new_fyear.date_start), )) result = cr.dictfetchall() fy_ids = [x['id'] for x in result] query_line = obj_acc_move_line._query_get( cr, uid, obj='account_move_line', context={'fiscalyear': fy_ids}) # create the opening move vals = { 'name': '/', 'ref': '', 'period_id': period.id, 'date': period.date_start, 'journal_id': new_journal.id, } move_id = obj_acc_move.create(cr, uid, vals, context=context) # 1. report of the accounts with defferal method == 'unreconciled' cr.execute( ''' SELECT a.id FROM account_account a LEFT JOIN account_account_type t ON (a.user_type_id = t.id) WHERE a.active AND a.type not in ('view', 'consolidation') AND a.company_id = %s AND t.close_method = %s''', ( company_id, 'unreconciled', )) account_ids = map(lambda x: x[0], cr.fetchall()) if account_ids: cr.execute( ''' INSERT INTO account_move_line ( name, create_uid, create_date, write_uid, write_date, statement_id, journal_id, currency_id, date_maturity, partner_id, blocked, credit, state, debit, ref, account_id, period_id, date, move_id, amount_currency, quantity, product_id, company_id) (SELECT name, create_uid, create_date, write_uid, write_date, statement_id, %s,currency_id, date_maturity, partner_id, blocked, credit, 'draft', debit, ref, account_id, %s, (%s) AS date, %s, amount_currency, quantity, product_id, company_id FROM account_move_line WHERE account_id IN %s AND ''' + query_line + ''' AND reconcile_id IS NULL)''', ( new_journal.id, period.id, period.date_start, move_id, tuple(account_ids), )) # We have also to consider all move_lines that were reconciled # on another fiscal year, and report them too cr.execute( ''' INSERT INTO account_move_line ( name, create_uid, create_date, write_uid, write_date, statement_id, journal_id, currency_id, date_maturity, partner_id, blocked, credit, state, debit, ref, account_id, period_id, date, move_id, amount_currency, quantity, product_id, company_id) (SELECT b.name, b.create_uid, b.create_date, b.write_uid, b.write_date, b.statement_id, %s, b.currency_id, b.date_maturity, b.partner_id, b.blocked, b.credit, 'draft', b.debit, b.ref, b.account_id, %s, (%s) AS date, %s, b.amount_currency, b.quantity, b.product_id, b.company_id FROM account_move_line b WHERE b.account_id IN %s AND b.reconcile_id IS NOT NULL AND b.period_id IN (''' + fy_period_set + ''') AND b.reconcile_id IN (SELECT DISTINCT(reconcile_id) FROM account_move_line a WHERE a.period_id IN (''' + fy2_period_set + ''')))''', ( new_journal.id, period.id, period.date_start, move_id, tuple(account_ids), )) self.invalidate_cache(cr, uid, context=context) # 2. report of the accounts with defferal method == 'detail' cr.execute( ''' SELECT a.id FROM account_account a LEFT JOIN account_account_type t ON (a.user_type_id= t.id) WHERE a.active AND a.type not in ('view', 'consolidation') AND a.company_id = %s AND t.close_method = %s''', ( company_id, 'detail', )) account_ids = map(lambda x: x[0], cr.fetchall()) if account_ids: cr.execute( ''' INSERT INTO account_move_line ( name, create_uid, create_date, write_uid, write_date, statement_id, journal_id, currency_id, date_maturity, partner_id, blocked, credit, state, debit, ref, account_id, period_id, date, move_id, amount_currency, quantity, product_id, company_id) (SELECT name, create_uid, create_date, write_uid, write_date, statement_id, %s,currency_id, date_maturity, partner_id, blocked, credit, 'draft', debit, ref, account_id, %s, (%s) AS date, %s, amount_currency, quantity, product_id, company_id FROM account_move_line WHERE account_id IN %s AND ''' + query_line + ''') ''', ( new_journal.id, period.id, period.date_start, move_id, tuple(account_ids), )) self.invalidate_cache(cr, uid, context=context) # 3. report of the accounts with defferal method == 'balance' cr.execute( ''' SELECT a.id FROM account_account a LEFT JOIN account_account_type t ON (a.user_type_id = t.id) WHERE a.active AND a.type not in ('view', 'consolidation') AND a.company_id = %s AND t.close_method = %s''', ( company_id, 'balance', )) account_ids = map(lambda x: x[0], cr.fetchall()) query_1st_part = """ INSERT INTO account_move_line ( debit, credit, name, date, move_id, journal_id, period_id, account_id, currency_id, amount_currency, company_id, state) VALUES """ query_2nd_part = "" query_2nd_part_args = [] for account in obj_acc_account.browse(cr, uid, account_ids, context={'fiscalyear': fy_id}): company_currency_id = self.pool.get('res.users').browse( cr, uid, uid).company_id.currency_id if not currency_obj.is_zero(cr, uid, company_currency_id, abs(account.balance)): if query_2nd_part: query_2nd_part += ',' query_2nd_part += "(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)" query_2nd_part_args += ( account.balance > 0 and account.balance or 0.0, account.balance < 0 and -account.balance or 0.0, data[0].report_name, period.date_start, move_id, new_journal.id, period.id, account.id, account.currency_id and account.currency_id.id or None, account.foreign_balance if account.currency_id else 0.0, account.company_id.id, 'draft') if query_2nd_part: cr.execute(query_1st_part + query_2nd_part, tuple(query_2nd_part_args)) self.invalidate_cache(cr, uid, context=context) # validate and centralize the opening move obj_acc_move.validate(cr, uid, [move_id], context=context) # reconcile all the move.line of the opening move ids = obj_acc_move_line.search( cr, uid, [('journal_id', '=', new_journal.id), ('period_id.fiscalyear_id', '=', new_fyear.id)]) if ids: reconcile_id = _reconcile_fy_closing(cr, uid, ids, context=context) # set the creation date of the reconcilation at the first day of the new fiscalyear, in order to have good figures in the aged trial balance self.pool.get('account.move.reconcile').write( cr, uid, [reconcile_id], {'create_date': new_fyear.date_start}, context=context) # create the journal.period object and link it to the old fiscalyear new_period = data[0].period_id.id ids = obj_acc_journal_period.search( cr, uid, [('journal_id', '=', new_journal.id), ('period_id', '=', new_period)]) if not ids: ids = [ obj_acc_journal_period.create( cr, uid, { 'name': (new_journal.name or '') + ':' + (period.code or ''), 'journal_id': new_journal.id, 'period_id': period.id }) ] cr.execute( 'UPDATE account_fiscalyear ' 'SET end_journal_period_id = %s ' 'WHERE id = %s', (ids[0], old_fyear.id)) obj_acc_fiscalyear.invalidate_cache(cr, uid, ['end_journal_period_id'], [old_fyear.id], context=context) return {'type': 'ir.actions.act_window_close'}