def create_chart(company=None, config=None): "Create chart of accounts" AccountTemplate = Model.get('account.account.template', config=config) ModelData = Model.get('ir.model.data') if not company: company = get_company() data, = ModelData.find([ ('module', '=', 'account'), ('fs_id', '=', 'account_template_root_en'), ], limit=1) account_template = AccountTemplate(data.db_id) create_chart = Wizard('account.create_chart') create_chart.execute('account') create_chart.form.account_template = account_template create_chart.form.company = company create_chart.execute('create_account') accounts = get_accounts(company, config=config) create_chart.form.account_receivable = accounts['receivable'] create_chart.form.account_payable = accounts['payable'] create_chart.execute('create_properties') return create_chart
def get_accounts(company=None, config=None): "Return accounts per kind" Account = Model.get('account.account', config=config) if not company: company = get_company() accounts = {} accounts['receivable'], = Account.find([ ('type.receivable', '=', True), ('company', '=', company.id), ], limit=1) accounts['payable'], = Account.find([ ('type.payable', '=', True), ('company', '=', company.id), ], limit=1) accounts['revenue'], = Account.find([ ('type.revenue', '=', True), ('company', '=', company.id), ], limit=1) accounts['expense'], = Account.find([ ('type.expense', '=', True), ('company', '=', company.id), ], limit=1) accounts['cash'], = Account.find([ ('company', '=', company.id), ('name', '=', 'Main Cash'), ], limit=1) accounts['tax'], = Account.find([ ('company', '=', company.id), ('name', '=', 'Main Tax'), ], limit=1) return accounts
def create_pos(company=None, config=None): "Create a Point of Sale" Pos = Model.get('account.pos', config=config) Sequence = Model.get('ir.sequence', config=config) if not company: company = get_company() pos = Pos( company=company.id, number=1, pos_type='manual', ) for attr, name in (('1', '01-Factura A'), ('2', '02-Nota de Debito A'), ('3', '03-Nota de Credito A'), ('6', '06-Factura B'), ('7', '07-Nota de Debito B'), ('8', '08-Nota de Credito B'), ('11', '11-Factura C'), ('12', '12-Nota de Debito C'), ('13', '13-Nota de Credito C')): sequence = Sequence(name='%s %s' % (name, 'manual'), code='account.invoice', company=company) sequence.save() pos.pos_sequences.new( invoice_type=attr, invoice_sequence=sequence, ) pos.save() return pos
def get_accounts(company=None, config=None): "Return accounts per kind" Account = Model.get('account.account', config=config) if not company: company = get_company() accounts = Account.find([ ('kind', 'in', ['receivable', 'payable', 'revenue', 'expense']), ('company', '=', company.id), ]) accounts = {a.kind: a for a in accounts} cash, = Account.find([ ('kind', '=', 'other'), ('company', '=', company.id), ('name', '=', 'Main Cash'), ]) accounts['cash'] = cash tax, = Account.find([ ('kind', '=', 'other'), ('company', '=', company.id), ('name', '=', 'Main Tax'), ]) accounts['tax'] = tax return accounts
def create_tax(rate, company=None, config=None): """Create a tax of rate""" Tax = Model.get('account.tax', config=config) existing_tax = Tax.find([('name', '=', DEFAULT_VAT_TAX_NAME)], limit=1) if existing_tax: print("Warning: Tax '" + DEFAULT_VAT_TAX_NAME + "' already exists!") return existing_tax[0] if not company: company = get_company() accounts = get_accounts(company) tax = Tax() tax.name = DEFAULT_VAT_TAX_NAME tax.description = tax.name tax.type = 'percentage' tax.rate = rate tax.invoice_account = accounts['tax'] tax.credit_note_account = accounts['tax'] tax.save() set_tax_code(tax) print("Success: Tax '" + DEFAULT_VAT_TAX_NAME + "' created!") return tax
def create_chart(company=None, config=None): """Create chart of accounts""" AccountTemplate = Model.get('account.account.template', config=config) ModelData = Model.get('ir.model.data') AccountChart = Model.get('account.account', config=config) existing_chart = AccountChart.find([('name', '=', CHART_OF_ACCOUNT_NAME)], limit=1) if existing_chart: print("Warning: Account Chart '" + CHART_OF_ACCOUNT_NAME + "' already exists!") return existing_chart[0] if not company: company = get_company() data, = ModelData.find([ ('module', '=', 'account'), ('fs_id', '=', 'account_template_root_en'), ], limit=1) account_template = AccountTemplate(data.db_id) create_chart = Wizard('account.create_chart') create_chart.execute('account') create_chart.form.account_template = account_template create_chart.form.company = company create_chart.execute('create_account') accounts = get_accounts(company, config=config) create_chart.form.account_receivable = accounts['receivable'] create_chart.form.account_payable = accounts['payable'] create_chart.execute('create_properties') print("Success: Account Chart '" + CHART_OF_ACCOUNT_NAME + "' created!") return create_chart
def create_fiscalyear(company=None, today=None, config=None): "Create a fiscal year for the company on today" FiscalYear = Model.get('account.fiscalyear', config=config) Sequence = Model.get('ir.sequence', config=config) SequenceType = Model.get('ir.sequence.type', config=config) if not company: company = get_company(config=config) if not today: today = datetime.date.today() fiscalyear = FiscalYear(name=str(today.year)) fiscalyear.start_date = today + relativedelta(month=1, day=1) fiscalyear.end_date = today + relativedelta(month=12, day=31) fiscalyear.company = company sequence_type, = SequenceType.find([('name', '=', "Account Move")], limit=1) post_move_sequence = Sequence(name=str(today.year), sequence_type=sequence_type, company=company) post_move_sequence.save() fiscalyear.post_move_sequence = post_move_sequence return fiscalyear
def create_fiscalyear(company=None, today=None, config=None): """Create a fiscal year for the company on today""" FiscalYear = Model.get('account.fiscalyear', config=config) Sequence = Model.get('ir.sequence', config=config) SequenceStrict = Model.get('ir.sequence.strict', config=config) if not company: company = get_company() if not today: today = datetime.date.today() existing_fy = FiscalYear.find([('name', '=', str(today.year))], limit=1) if existing_fy: print("Warning: Fiscal year " + str(today.year) + " already exists!") return existing_fy[0] fiscalyear = FiscalYear(name=str(today.year)) fiscalyear.start_date = today + relativedelta(month=1, day=1) fiscalyear.end_date = today + relativedelta(month=12, day=31) fiscalyear.company = company fiscalyear.account_stock_method = ACCOUNT_STOCK_METHOD post_move_sequence = Sequence(name=POST_MOVE_SEQ, code='account.move', number_next=10000, company=company) customer_invoice_sequence = SequenceStrict(name=CUSTOMER_INVOICE_SEQ, code='account.invoice', number_next=200000, company=company) customer_credit_note_sequence = SequenceStrict( name=CUSTOMER_CREDIT_NOTE_SEQ, code='account.invoice', number_next=100000, company=company) supplier_invoice_sequence = SequenceStrict(name=SUPPLIER_INVOICE_SEQ, code='account.invoice', number_next=600000, company=company) supplier_credit_note_sequence = SequenceStrict( name=SUPPLIER_CREDIT_NOTE_SEQ, code='account.invoice', number_next=500000, company=company) post_move_sequence.save() customer_invoice_sequence.save() customer_credit_note_sequence.save() supplier_invoice_sequence.save() supplier_credit_note_sequence.save() fiscalyear.post_move_sequence = post_move_sequence fiscalyear.out_invoice_sequence = customer_invoice_sequence fiscalyear.out_credit_note_sequence = customer_credit_note_sequence fiscalyear.in_invoice_sequence = supplier_invoice_sequence fiscalyear.in_credit_note_sequence = supplier_credit_note_sequence fiscalyear.save() fiscalyear.click('create_period') period = fiscalyear.periods[0] print("Success: Fiscal year " + str(today.year) + "' created!") return fiscalyear
def create_tax(rate, company=None, config=None): """Create a tax of rate""" Tax = Model.get('account.tax', config=config) existing_tax = Tax.find([('name', '=', DEFAULT_VAT_TAX_NAME)], limit=1) if existing_tax: print("Warning: Tax '" + DEFAULT_VAT_TAX_NAME + "' already exists!") return existing_tax[0] if not company: company = get_company() accounts = get_accounts(company) tax = Tax() tax.name = DEFAULT_VAT_TAX_NAME tax.description = tax.name tax.type = 'percentage' tax.rate = rate tax.invoice_account = accounts['tax'] tax.credit_note_account = accounts['tax'] tax.save() set_tax_code(tax) print("Success: Tax '" + DEFAULT_VAT_TAX_NAME + "' created!") return tax
def create_chart(company=None, config=None): "Create chart of accounts" AccountTemplate = Model.get('account.account.template', config=config) ModelData = Model.get('ir.model.data') if not company: company = get_company() data, = ModelData.find([ ('module', '=', 'account'), ('fs_id', '=', 'account_template_root_en'), ], limit=1) account_template = AccountTemplate(data.db_id) create_chart = Wizard('account.create_chart') create_chart.execute('account') create_chart.form.account_template = account_template create_chart.form.company = company create_chart.execute('create_account') accounts = get_accounts(company, config=config) create_chart.form.account_receivable = accounts['receivable'] create_chart.form.account_payable = accounts['payable'] create_chart.execute('create_properties') return create_chart
def get_accounts(company=None, config=None): "Return accounts per kind" Account = Model.get('account.account', config=config) if not company: company = get_company() accounts = Account.find([ ('kind', 'in', ['receivable', 'payable', 'revenue', 'expense']), ('company', '=', company.id), ]) accounts = {a.kind: a for a in accounts} cash, = Account.find([ ('kind', '=', 'other'), ('company', '=', company.id), ('name', '=', 'Main Cash'), ]) accounts['cash'] = cash tax, = Account.find([ ('kind', '=', 'other'), ('company', '=', company.id), ('name', '=', 'Main Tax'), ]) accounts['tax'] = tax return accounts
def get_accounts(company=None, config=None): "Return accounts per kind" Account = Model.get('account.account', config=config) if not company: company = get_company(config=config) accounts = {} for type in ['receivable', 'payable', 'revenue', 'expense']: try: accounts[type], = Account.find([ ('type.%s' % type, '=', True), ('company', '=', company.id), ], limit=1) except ValueError: pass try: accounts['cash'], = Account.find([ ('company', '=', company.id), ('name', '=', 'Main Cash'), ], limit=1) except ValueError: pass try: accounts['tax'], = Account.find([ ('company', '=', company.id), ('name', '=', 'Main Tax'), ], limit=1) except ValueError: pass return accounts
def set_lims_configuration(company=None, config=None): "Set Lims Configuration" if not company: company = get_company() # Create fraction product ProductUom = Model.get('product.uom', config=config) unit, = ProductUom.find([('name', '=', 'Unit')]) ProductTemplate = Model.get('product.template', config=config) Product = Model.get('product.product', config=config) fraction_product = Product() fraction_template = ProductTemplate() fraction_template.name = 'Fraction' fraction_template.default_uom = unit fraction_template.type = 'goods' fraction_template.list_price = Decimal('1') fraction_template.cost_price = Decimal('1') fraction_template.save() fraction_product.template = fraction_template fraction_product.save() # Create analysis product category ProductCategory = Model.get('product.category', config=config) analysis_product_category = ProductCategory() analysis_product_category.name = 'Analysis Services' analysis_product_category.save() # Create default notebook view default_notebook_view = _create_default_notebook_view(config) # Create required sequences SequenceType = Model.get('ir.sequence.type', config=config) Sequence = Model.get('ir.sequence', config=config) planification_sequence_type, = SequenceType.find([ ('name', '=', 'Planification'), ], limit=1) planification_sequence = Sequence( name='Planification Sequence', sequence_type=planification_sequence_type, company=company, ) planification_sequence.save() # Set Lims configuration LimsConfiguration = Model.get('lims.configuration', config=config) lims_config, = LimsConfiguration.find() lims_config.fraction_product = fraction_product lims_config.analysis_product_category = analysis_product_category lims_config.default_notebook_view = default_notebook_view lims_config.planification_sequence = planification_sequence Lang = Model.get('ir.lang', config=config) lang_en, = Lang.find([('code', '=', 'en')]) lang_en.translatable = True lang_en.save() lims_config.results_report_language = lang_en lims_config.save()
def get_pos(company=None, config=None): "Return the only pos" Pos = Model.get('account.pos', config=config) if not company: company = get_company() pos, = Pos.find([('company', '=', company.id)]) return pos
def create_pos(company=None, type='manual', number=1, ws=None, config=None): "Create a Point of Sale" Pos = Model.get('account.pos', config=config) Sequence = Model.get('ir.sequence', config=config) if not company: company = get_company() pos = Pos( company=company.id, number=number, pos_type=type, pyafipws_electronic_invoice_service=ws, ) for attr, name in ( ('1', '01-Factura A'), ('2', '02-Nota de Debito A'), ('3', '03-Nota de Credito A'), ('4', '04-Recibos A'), ('5', '05-Nota de Venta al Contado A'), ('6', '06-Factura B'), ('7', '07-Nota de Debito B'), ('8', '08-Nota de Credito B'), ('9', '09-Recibos B'), ('10', '10-Notas de Venta al Contado B'), ('11', '11-Factura C'), ('12', '12-Nota de Debito C'), ('13', '13-Nota de Credito C'), ('15', '15-Recibo C'), ('19', '19-Factura E'), ('20', '20-Nota de Débito E'), ('21', '21-Nota de Crédito E'), ('201', '201-Factura de Crédito Electrónica MiPyMEs (FCE) A'), ('202', '202-Nota de Débito Electrónica MiPyMEs (FCE) A'), ('203', '203-Nota de Crédito Electrónica MiPyMEs (FCE) A'), ('206', '206-Factura de Crédito Electrónica MiPyMEs (FCE) B'), ('207', '207-Nota de Débito Electrónica MiPyMEs (FCE) B'), ('208', '208-Nota de Crédito Electrónica MiPyMEs (FCE) B'), ('211', '211-Factura de Crédito Electrónica MiPyMEs (FCE) C'), ('212', '212-Nota de Débito Electrónica MiPyMEs (FCE) C'), ('213', '213-Nota de Crédito Electrónica MiPyMEs (FCE) C')): sequence = Sequence( name='%s %s' % (name, type), code='account.invoice', company=company) sequence.save() pos.pos_sequences.new( invoice_type=attr, invoice_sequence=sequence, ) pos.save() return pos
def add_advance_payment_accounts(accounts, company=None, config=None): "Add advance payment to accounts" Account = Model.get('account.account', config=config) if not company: company = get_company() accounts['advance_payment'], = Account.find([ ('type.unearned_revenue', '=', True), ('company', '=', company.id), ], limit=1) return accounts
def add_cogs_accounts(accounts, company=None, config=None): "Add COGS to accounts" Account = Model.get('account.account', config=config) if not company: company = get_company() accounts['cogs'], = Account.find([ ('kind', '=', 'other'), ('company', '=', company.id), ('name', '=', 'COGS'), ]) return accounts
def _create_company_contacts(company=None, config=None): "Create contacts for company party" if not company: company = get_company() Address = Model.get('party.address', config=config) address, = Address.find([('party', '=', company.party.id)]) address.invoice_contact = True address.report_contact = True address.acknowledgment_contact = True address.email = '*****@*****.**' address.save() return address
def add_cogs_accounts(accounts, company=None, config=None): "Add COGS to accounts" Account = Model.get('account.account', config=config) if not company: company = get_company() accounts['cogs'], = Account.find([ ('type.expense', '=', True), ('id', '!=', accounts['expense'].id), ('company', '=', company.id), ]) return accounts
def get_pos(company=None, type='manual', number=1, config=None): "Return the only pos" Pos = Model.get('account.pos', config=config) if not company: company = get_company() pos, = Pos.find([ ('company', '=', company.id), ('pos_type', '=', type), ('number', '=', number), ]) return pos
def set_afip_certs(company=None, config=None): "Set AFIP certificates" if not company: company = get_company() with file_open('account_invoice_ar/tests/gcoop.crt', mode='rb') as fp: crt = fp.read() company.pyafipws_certificate = crt.decode('utf8') with file_open('account_invoice_ar/tests/gcoop.key', mode='rb') as fp: key = fp.read() company.pyafipws_private_key = key.decode('utf8') company.pyafipws_mode_cert = 'homologacion' company.save() return company
def add_cogs_accounts(accounts, company=None, config=None): "Add COGS to accounts" Account = Model.get('account.account', config=config) if not company: company = get_company() accounts['cogs'], = Account.find([ ('kind', '=', 'other'), ('company', '=', company.id), ('name', '=', 'COGS'), ]) return accounts
def add_deposit_accounts(accounts, company=None, config=None): 'Add deposit to accounts' Account = Model.get('account.account', config=config) if not company: company = get_company() accounts['deposit'], = Account.find([ ('kind', '=', 'deposit'), ('company', '=', company.id), ('name', '=', 'Deposit'), ]) return accounts
def done(context): from trytond.modules.company.tests.tools import create_company, \ get_company from trytond.modules.account.tests.tools import create_fiscalyear, \ create_chart, get_accounts from.trytond.modules.account_invoice.tests.tools import \ set_fiscalyear_invoice_sequences, create_payment_term from trytond.modules.account_asset.tests.tools \ import add_asset_accounts #step('Create database') config = config.set_trytond() config.pool.test = True #step('Install account_asset') Module = Model.get('ir.module.module') module, = Module.find([ ('name', '=', 'account_asset'), ]) module.click('install') Wizard('ir.module.module.install_upgrade').execute('upgrade') #@step('Create company') _ = create_company() company = get_company() #@step('Reload the context') User = Model.get('res.user') config._context = User.get_preferences(True, config.context) #@step('Create fiscal year') fiscalyear = set_fiscalyear_invoice_sequences( create_fiscalyear(company)) fiscalyear.click('create_period') #@step('Create chart of accounts') _ = create_chart(company) accounts = add_asset_accounts(get_accounts(company), company) revenue = accounts['revenue'] asset_account = accounts['asset'] expense = accounts['expense'] depreciation_account = accounts['depreciation']
def get_invoice_types(company=None, pos=None, config=None): "Return invoices types per pos and company" PosSequence = Model.get('account.pos.sequence', config=config) if not company: company = get_company() if not pos: pos = get_pos(company) invoice_types = PosSequence.find([ ('pos', '=', pos.id), ]) invoice_types = {i.invoice_type: i for i in invoice_types} return invoice_types
def add_stock_accounts(accounts, company=None, config=None): "Add stock kind to accounts" Account = Model.get('account.account', config=config) if not company: company = get_company() stock_accounts = Account.find([ ('kind', '=', 'stock'), ('company', '=', company.id), ]) for account in stock_accounts: name = account.name.lower().replace(' and ', '_').replace(' ', '_') accounts[name] = account return accounts
def main(): company = get_company() fiscalyear = create_fiscalyear(company) _ = create_chart(company) accounts = get_accounts(company) payable = accounts['payable'] expense = accounts['expense'] tax = accounts['tax'] tax = create_tax(Decimal(DEFAULT_VAT_TAX_PERCENTAGE)) create_account_configuration(accounts, company) create_payment_terms() supplier = create_supplier() # create product config create_product_config() create_product_category(accounts)
def main(): company = get_company() fiscalyear = create_fiscalyear(company) _ = create_chart(company) accounts = get_accounts(company) payable = accounts['payable'] expense = accounts['expense'] tax = accounts['tax'] tax = create_tax(Decimal(DEFAULT_VAT_TAX_PERCENTAGE)) create_account_configuration(accounts, company) create_payment_terms() supplier = create_supplier() # create product config create_product_config() create_product_category(accounts)
def add_stock_accounts(accounts, company=None, config=None): "Add stock kind to accounts" Account = Model.get('account.account', config=config) if not company: company = get_company(config=config) stock_accounts = Account.find([ ('type.stock', '=', True), ('company', '=', company.id), ]) for account in stock_accounts: name = account.name.lower().replace(' and ', '_').replace(' ', '_') accounts[name] = account return accounts
def create_fiscalyear(company=None, today=None, config=None): """Create a fiscal year for the company on today""" FiscalYear = Model.get('account.fiscalyear', config=config) Sequence = Model.get('ir.sequence', config=config) SequenceStrict = Model.get('ir.sequence.strict', config=config) if not company: company = get_company() if not today: today = datetime.date.today() existing_fy = FiscalYear.find([('name', '=', str(today.year))], limit=1) if existing_fy: print("Warning: Fiscal year " + str(today.year) + " already exists!") return existing_fy[0] fiscalyear = FiscalYear(name=str(today.year)) fiscalyear.start_date = today + relativedelta(month=1, day=1) fiscalyear.end_date = today + relativedelta(month=12, day=31) fiscalyear.company = company fiscalyear.account_stock_method = ACCOUNT_STOCK_METHOD post_move_sequence = Sequence(name=POST_MOVE_SEQ, code='account.move', number_next=10000, company=company) customer_invoice_sequence = SequenceStrict(name=CUSTOMER_INVOICE_SEQ, code='account.invoice', number_next=200000, company=company) customer_credit_note_sequence = SequenceStrict(name=CUSTOMER_CREDIT_NOTE_SEQ, code='account.invoice', number_next=100000, company=company) supplier_invoice_sequence = SequenceStrict(name=SUPPLIER_INVOICE_SEQ, code='account.invoice', number_next=600000, company=company) supplier_credit_note_sequence = SequenceStrict(name=SUPPLIER_CREDIT_NOTE_SEQ, code='account.invoice', number_next=500000, company=company) post_move_sequence.save() customer_invoice_sequence.save() customer_credit_note_sequence.save() supplier_invoice_sequence.save() supplier_credit_note_sequence.save() fiscalyear.post_move_sequence = post_move_sequence fiscalyear.out_invoice_sequence = customer_invoice_sequence fiscalyear.out_credit_note_sequence = customer_credit_note_sequence fiscalyear.in_invoice_sequence = supplier_invoice_sequence fiscalyear.in_credit_note_sequence = supplier_credit_note_sequence fiscalyear.save() fiscalyear.click('create_period') period = fiscalyear.periods[0] print("Success: Fiscal year " + str(today.year) + "' created!") return fiscalyear
def create_retencion_sequence(company=None, config=None): "Create retencion sequence" SequenceType = Model.get('ir.sequence.type', config=config) Sequence = Model.get('ir.sequence', config=config) if not company: company = get_company() retencion_seq_type, = SequenceType.find([ ('name', '=', 'Account Retencion'), ], limit=1) retencion_seq = Sequence(name='Retencion', sequence_type=retencion_seq_type, company=company) retencion_seq.save() return retencion_seq
def create_tax(rate, company=None, config=None): "Create a tax of rate" Tax = Model.get('account.tax', config=config) if not company: company = get_company() accounts = get_accounts(company) tax = Tax() tax.name = 'Tax %s' % rate tax.description = tax.name tax.type = 'percentage' tax.rate = rate tax.invoice_account = accounts['tax'] tax.credit_note_account = accounts['tax'] return tax
def get_wsfexv1(company=None, config=None): "return wsfexv1 object" if not company: company = get_company() company = set_afip_certs(company, config) URL_WSAA = "https://wsaahomo.afip.gov.ar/ws/services/LoginCms?wsdl" URL_WSFEXv1 = "https://wswhomo.afip.gov.ar/wsfexv1/service.asmx?WSDL" crt = get_filename('party_ar/tests/gcoop.crt') key = get_filename('party_ar/tests/gcoop.key') ta = WSAA().Autenticar('wsfex', crt, key, URL_WSAA, cacert=True) wsfexv1 = WSFEXv1() wsfexv1.LanzarExcepciones = True wsfexv1.SetTicketAcceso(ta) wsfexv1.Cuit = company.party.vat_number wsfexv1.Conectar(wsdl=URL_WSFEXv1, cacert=True) return wsfexv1
def create_tax(rate, company=None, config=None): "Create a tax of rate" Tax = Model.get('account.tax', config=config) if not company: company = get_company() accounts = get_accounts(company) tax = Tax() tax.name = 'Tax %s' % rate tax.description = tax.name tax.type = 'percentage' tax.rate = rate tax.invoice_account = accounts['tax'] tax.credit_note_account = accounts['tax'] return tax
def add_asset_accounts(accounts, company=None, config=None): "Add asset kind to accounts" Account = Model.get('account.account', config=config) if not company: company = get_company() accounts['asset'], = Account.find([ ('type.fixed_asset', '=', True), ('name', '=', "Assets"), ('company', '=', company.id), ], limit=1) accounts['depreciation'], = Account.find([ ('type.fixed_asset', '=', True), ('name', '=', "Depreciation"), ('company', '=', company.id), ], limit=1) return accounts
def get_invoice_types(company=None, pos=None, config=None): "Return invoices types per pos and company" Account = Model.get('account.account', config=config) PosSequence = Model.get('account.pos.sequence', config=config) if not company: company = get_company() if not pos: pos = get_pos(company) accounts = Account.find([ ('kind', 'in', ['receivable', 'payable', 'revenue', 'expense']), ('company', '=', company.id), ]) invoice_types = PosSequence.find([ ('pos', '=', pos.id), ]) invoice_types = {i.invoice_type: i for i in invoice_types} return invoice_types
def create_chart(company=None, config=None): "Create chart of accounts" AccountTemplate = Model.get('account.account.template', config=config) if not company: company = get_company() account_template, = AccountTemplate.find([('parent', '=', None)]) create_chart = Wizard('account.create_chart') create_chart.execute('account') create_chart.form.account_template = account_template create_chart.form.company = company create_chart.execute('create_account') accounts = get_accounts(company, config=config) create_chart.form.account_receivable = accounts['receivable'] create_chart.form.account_payable = accounts['payable'] create_chart.execute('create_properties') return create_chart
def create_fiscalyear(company=None, today=None, config=None): "Create a fiscal year for the company on today" FiscalYear = Model.get('account.fiscalyear', config=config) Sequence = Model.get('ir.sequence', config=config) if not company: company = get_company() if not today: today = datetime.date.today() fiscalyear = FiscalYear(name=str(today.year)) fiscalyear.start_date = today + relativedelta(month=1, day=1) fiscalyear.end_date = today + relativedelta(month=12, day=31) fiscalyear.company = company post_move_sequence = Sequence(name=str(today.year), code='account.move', company=company) post_move_sequence.save() fiscalyear.post_move_sequence = post_move_sequence return fiscalyear
def add_asset_accounts(accounts, company=None, config=None): "Add asset kind to accounts" Account = Model.get('account.account', config=config) if not company: company = get_company() expense_accounts = Account.find([ ('kind', '=', 'expense'), ('company', '=', company.id), ]) for account in expense_accounts: if account.name == 'Expense': accounts['expense'] = account elif account.name == 'Assets': accounts['asset'] = account depreciation, = Account.find([ ('kind', '=', 'other'), ('name', '=', 'Depreciation'), ]) accounts['depreciation'] = depreciation return accounts
def add_asset_accounts(accounts, company=None, config=None): "Add asset kind to accounts" Account = Model.get('account.account', config=config) if not company: company = get_company() expense_accounts = Account.find([ ('kind', '=', 'expense'), ('company', '=', company.id), ]) for account in expense_accounts: if account.name == 'Expense': accounts['expense'] = account elif account.name == 'Assets': accounts['asset'] = account depreciation, = Account.find([ ('kind', '=', 'other'), ('name', '=', 'Depreciation'), ]) accounts['depreciation'] = depreciation return accounts
def get_accounts(company=None, config=None): "Return accounts per kind" Account = Model.get('account.account', config=config) if not company: company = get_company(config=config) accounts = {} accounts['receivable'], = Account.find([ ('type.receivable', '=', True), ('company', '=', company.id), ('code', '=', '4111'), ], limit=1) accounts['payable'], = Account.find([ ('type.payable', '=', True), ('company', '=', company.id), ('code', '=', '4011'), ], limit=1) accounts['revenue'], = Account.find([ ('type.revenue', '=', True), ('company', '=', company.id), ('code', '=', '7011'), ], limit=1) accounts['expense'], = Account.find([ ('type.expense', '=', True), ('company', '=', company.id), ('code', '=', '6071'), ], limit=1) accounts['cash'], = Account.find([ ('company', '=', company.id), ('code', '=', '5311'), ]) accounts['tax'], = Account.find([ ('company', '=', company.id), ('code', '=', '44558'), ]) return accounts
def create_chart(company=None, config=None): """Create chart of accounts""" AccountTemplate = Model.get('account.account.template', config=config) ModelData = Model.get('ir.model.data') AccountChart = Model.get('account.account', config=config) existing_chart = AccountChart.find([('name', '=', CHART_OF_ACCOUNT_NAME)], limit=1) if existing_chart: print("Warning: Account Chart '" + CHART_OF_ACCOUNT_NAME + "' already exists!") return existing_chart[0] if not company: company = get_company() data, = ModelData.find([ ('module', '=', 'account'), ('fs_id', '=', 'account_template_root_en'), ], limit=1) account_template = AccountTemplate(data.db_id) create_chart = Wizard('account.create_chart') create_chart.execute('account') create_chart.form.account_template = account_template create_chart.form.company = company create_chart.execute('create_account') accounts = get_accounts(company, config=config) create_chart.form.account_receivable = accounts['receivable'] create_chart.form.account_payable = accounts['payable'] create_chart.execute('create_properties') print("Success: Account Chart '" + CHART_OF_ACCOUNT_NAME + "' created!") return create_chart
def create_account_configuration(accounts=None, company=None): if not company: company = get_company() # account.configuration Sequence = Model.get('ir.sequence') sequence = Sequence.find([('code', '=', 'account.payment.group')]) ACModel = Model.get('ir.model') acmodel = ACModel.find([('model', '=', 'account.configuration')]) ACModelField = Model.get('ir.model.field') acmodelfield = ACModelField.find([('name', '=', 'payment_group_sequence'), ('model', '=', acmodel[0].id)]) AccountConfiguration = Model.get('account.configuration') existing = AccountConfiguration.find([('id', '>', '0')]) if existing: print('Warning: Account configuration already exists!') return else: print('Creating account configuration.') accountconfiguration = AccountConfiguration() accountconfiguration.save() Property = Model.get('ir.property') acproperty = Property() acproperty.res = accountconfiguration acproperty.value = sequence[0] acproperty.field = acmodelfield[0] acproperty.save() acproperty = Property() ACModelField = Model.get('ir.model.field') acmodelfield = ACModelField.find([('name', '=', 'cost_price_counterpart_account'), ('model', '=', acmodel[0].id)]) acproperty.res = accountconfiguration acproperty.value = accounts['cogs'] acproperty.field = acmodelfield[0] acproperty.save() acproperty = Property() ACModelField = Model.get('ir.model.field') acmodelfield = ACModelField.find([('name', '=', 'stock_journal'), ('model', '=', acmodel[0].id)]) acproperty.res = accountconfiguration acproperty.value = accounts['expense'] acproperty.field = acmodelfield[0] acproperty.save() ModelField = Model.get('ir.model.field') modelfield = ModelField.find([('name', '=', 'cost_price_counterpart_account')]) if modelfield: Property = Model.get('ir.property') property = Property.find([('field', '=', modelfield[0].id), ('value', 'like', 'account.account,%')]) if len(property) == 0: property = Property() # property.rec_name = 'account.account' property.field = modelfield[0] property.value = accounts['cogs'] property.company = company property.save() RootModel = Model.get('ir.model') rootmodel = RootModel.find([('model', '=', 'product.template')]) modelfield = ModelField.find([('name', '=', 'account_revenue'), ('model', '=', rootmodel[0].id)]) if modelfield: Property = Model.get('ir.property') property = Property.find([('field', '=', modelfield[0].id), ('value', 'like', 'account.account,%')]) if len(property) == 0: property = Property() # property.rec_name = 'account.account' property.field = modelfield[0] property.value = accounts['revenue'] property.company = company property.save() modelfield = ModelField.find([('name', '=', 'account_expense'), ('model', '=', rootmodel[0].id)]) if modelfield: Property = Model.get('ir.property') property = Property.find([('field', '=', modelfield[0].id), ('value', 'like', 'account.account,%')]) if len(property) == 0: property = Property() # property.rec_name = 'account.account' property.field = modelfield[0] property.value = accounts['expense'] property.company = company property.save() rootmodel = RootModel.find([('model', '=', 'product.category')]) modelfield = ModelField.find([('name', '=', 'account_revenue'), ('model', '=', rootmodel[0].id)]) if modelfield: Property = Model.get('ir.property') property = Property.find([('field', '=', modelfield[0].id), ('value', 'like', 'account.account,%')]) if len(property) == 0: property = Property() # property.rec_name = 'account.account' property.field = modelfield[0] property.value = accounts['revenue'] property.company = company property.save() modelfield = ModelField.find([('name', '=', 'account_expense'), ('model', '=', rootmodel[0].id)]) if modelfield: Property = Model.get('ir.property') property = Property.find([('field', '=', modelfield[0].id), ('value', 'like', 'account.account,%')]) if len(property) == 0: property = Property() # property.rec_name = 'account.account' property.field = modelfield[0] property.value = accounts['expense'] property.company = company property.save() rootmodel = RootModel.find([('model', '=', 'party.party')]) modelfield = ModelField.find([('name', '=', 'account_payable'), ('model', '=', rootmodel[0].id)]) if modelfield: Property = Model.get('ir.property') property = Property.find([('field', '=', modelfield[0].id), ('res', 'not like', 'party.party,%')]) if len(property) == 0: property = Property() # property.rec_name = 'account.account' property.field = modelfield[0] property.value = accounts['payable'] property.company = company property.save() modelfield = ModelField.find([('name', '=', 'account_receivable'), ('model', '=', rootmodel[0].id)]) if modelfield: Property = Model.get('ir.property') property = Property.find([('field', '=', modelfield[0].id), ('res', 'not like', 'party.party,%')]) if len(property) == 0: property = Property() # property.rec_name = 'account.account' property.field = modelfield[0] property.value = accounts['receivable'] property.company = company property.save()
def create_product_category(accounts): Category = Model.get('product.category') duplicate = Category.find([('name', '=', DEFAULT_PRODUCT_CATEGORY)]) if duplicate: print('Warning: category ' + duplicate[0].name + ' already exists!') else: category = Category() category.name = DEFAULT_PRODUCT_CATEGORY category.accounting = True category.taxes_parent = False category.account_parent = False Tax = Model.get('account.tax') tax = Tax.find([('name', '=', DEFAULT_VAT_TAX_NAME)], limit=1) category.supplier_taxes.append(tax[0]) tax = Tax.find([('name', '=', DEFAULT_VAT_TAX_NAME)], limit=1) category.customer_taxes.append(tax[0]) category.save() print("Success: Product category '" + DEFAULT_PRODUCT_CATEGORY + "' created!") Account = Model.get('account.account') stockaccountlist = Account.find([('kind', '=', 'stock')]) PCModel = Model.get('ir.model') pcmodel = PCModel.find([('model', '=', 'product.category')]) ModelField = Model.get('ir.model.field') modelfield = ModelField.find([('name', '=', 'account_expense'), ('model', '=', pcmodel[0].id)]) Property = Model.get('ir.property') property = Property.find([('field', '=', modelfield[0].id), ('res', 'not like', 'product.category,%')]) if len(property) == 0: property = Property() # property.rec_name = 'account.account' property.field = modelfield[0] property.value = accounts['expense'] property.company = get_company() property.save() else: return modelfield = ModelField.find([('name', '=', 'account_revenue'), ('model', '=', pcmodel[0].id)]) property = Property() property.field = modelfield[0] property.value = accounts['revenue'] property.company = get_company() property.save() modelfield = ModelField.find([('name', '=', 'account_stock'), ('model', '=', pcmodel[0].id)]) property = Property() property.field = modelfield[0] property.value = get_account(stockaccountlist, 'Stock') property.company = get_company() property.save() modelfield = ModelField.find([('name', '=', 'account_cogs'), ('model', '=', pcmodel[0].id)]) property = Property() property.field = modelfield[0] property.value = accounts['cogs'] property.company = get_company() property.save() modelfield = ModelField.find([('name', '=', 'account_stock_lost_found'), ('model', '=', pcmodel[0].id)]) property = Property() property.field = modelfield[0] property.value = get_account(stockaccountlist, 'Stock Lost and Found') property.company = get_company() property.save() modelfield = ModelField.find([('name', '=', 'account_stock_supplier'), ('model', '=', pcmodel[0].id)]) property = Property() property.field = modelfield[0] property.value = get_account(stockaccountlist, 'Stock Supplier') property.company = get_company() property.save() modelfield = ModelField.find([('name', '=', 'account_stock_production'), ('model', '=', pcmodel[0].id)]) property = Property() property.field = modelfield[0] property.value = get_account(stockaccountlist, 'Stock Production') property.company = get_company() property.save() modelfield = ModelField.find([('name', '=', 'account_stock_customer'), ('model', '=', pcmodel[0].id)]) property = Property() property.field = modelfield[0] property.value = get_account(stockaccountlist, 'Stock Customer') property.company = get_company() property.save()