本文整理汇总了Python中proteus.Model类的典型用法代码示例。如果您正苦于以下问题:Python Model类的具体用法?Python Model怎么用?Python Model使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Model类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: install_modules
def install_modules():
print u'\n>>> instalando modulos...'
Module = Model.get('ir.module.module')
modules_to_install=[
'account_ar',
'account_voucher_ar',
'account_check_ar',
'account_bank_ar',
'account_retencion_ar',
'account_coop_ar',
'company_logo',
'account_invoice_ar',
]
modules = Module.find([
('name', 'in', modules_to_install),
])
for module in modules:
module.click('install')
Wizard('ir.module.module.install_upgrade').execute('upgrade')
print u'\n>>> wizards de configuracion se marcan como done...'
ConfigWizardItem = Model.get('ir.module.module.config_wizard.item')
for item in ConfigWizardItem.find([('state', '!=', 'done')]):
item.state = 'done'
item.save()
示例2: test_save
def test_save(self):
User = Model.get('res.user')
test = User()
test.name = 'Test'
test.login = 'test'
test.save()
self.assert_(test.id > 0)
test = User(test.id)
self.assertEqual(test.name, 'Test')
self.assertEqual(test.login, 'test')
self.assert_(test.active)
test.signature = 'Test signature'
self.assertEqual(test.signature, 'Test signature')
test.save()
self.assertEqual(test.signature, 'Test signature')
test = User(test.id)
self.assertEqual(test.signature, 'Test signature')
Group = Model.get('res.group')
test2 = User(name='Test 2', login='test2',
groups=[Group(name='Test 2')])
test2.save()
self.assert_(test2.id > 0)
self.assertEqual(test2.name, 'Test 2')
self.assertEqual(test2.login, 'test2')
示例3: loadCustomers
def loadCustomers():
f = open(sys.argv[2], 'rb')
countrycode = sys.argv[3]
if countrycode is None:
print "Please provide a country code. e.g. 'CH'"
try:
reader = csv.DictReader(f)
Lang = Model.get('ir.lang')
(en,) = Lang.find([('code', '=', 'en_US')])
Country = Model.get('country.country')
(ch, ) = Country.find([('code', '=', countrycode)])
for row in reader:
print(row['first_name'], row['last_name'], row['company_name'])
Party = Model.get('party.party')
party = Party()
if party.id < 0:
party.name = row['company_name']
party.lang = en
party.addresses[0].name = row['first_name']+' '+row['last_name']
party.addresses[0].street = row['address']
party.addresses[0].streetbis = None
party.addresses[0].zip = row['zip']
party.addresses[0].city = row['city']
party.addresses[0].country = ch
# party.addresses[0].subdivision = row['state']
party.addresses[0].invoice = True
party.addresses[0].delivery = True
party.save()
finally:
f.close()
示例4: test_default_set
def test_default_set(self):
User = Model.get('res.user')
Group = Model.get('res.group')
group_ids = [x.id for x in Group.find()]
test = User()
test._default_set({
'name': 'Test',
'groups': group_ids,
})
self.assertEqual(test.name, 'Test')
self.assertEqual([x.id for x in test.groups], group_ids)
test = User()
test._default_set({
'name': 'Test',
'groups': [
{
'name': 'Group 1',
},
{
'name': 'Group 2',
},
],
})
self.assertEqual(test.name, 'Test')
self.assertEqual([x.name for x in test.groups], ['Group 1', 'Group 2'])
示例5: crear_inmuebles
def crear_inmuebles():
Address = Model.get("party.address")
address = Address.find([])
for item in address:
print item.street
new_inmueble = Model.get('sigcoop_inmueble.inmueble')()
if len(item.street)==0:
new_inmueble.calle_dom = 'SIN DATOS'
else:
new_inmueble.calle_dom = item.street
if len(item.streetbis)==0:
new_inmueble.numero_dom = '0'
else:
new_inmueble.numero_dom = item.streetbis
new_inmueble.localidad_dom = 'PUAN'
new_inmueble.partido_dom = 'PUAN'
new_inmueble.cp_dom = '8180'
new_inmueble.save()
inmuebleid = new_inmueble.id
#crea la relacion con party
crear_relacion_titular(inmuebleid, item.party.id)
示例6: create_entity
def create_entity(values):
if not values.get("model"):
print "Falta el modelo. Que estamos haciendo??"
return None
if (values.get("id") is None):
print "Falta el id. Que estamos haciendo??"
return None
model = values.pop("model")
_id = values.pop("id")
print "Creando la entidad %s para el registro numero %s" % (model, _id)
#Contructor del modelo
const = Model.get(model)
entity = const()
save_for_last = []
for k,v in values.iteritems():
if (isinstance(v, tuple)):
ref = Model.get(v[0]).find(v[1])[0]
setattr(entity, k, ref)
elif (isinstance(v, list)):
constructor = Model.get(v[0])
to_save = []
for elem in v[1]:
to_save.append(constructor.find([elem])[0])
save_for_last.append((k, to_save))
else:
setattr(entity, k, v)
for i in save_for_last:
getattr(entity, i[0]).extend(i[1])
entity.save()
return entity
示例7: create_chart
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
示例8: test_on_change_set
def test_on_change_set(self):
User = Model.get('res.user')
Group = Model.get('res.group')
test = User()
test._on_change_set('name', 'Test')
self.assertEqual(test.name, 'Test')
group_ids = [x.id for x in Group.find()]
test._on_change_set('groups', group_ids)
self.assertEqual([x.id for x in test.groups], group_ids)
test._on_change_set('groups', {'remove': [group_ids[0]]})
self.assertEqual([x.id for x in test.groups], group_ids[1:])
test._on_change_set('groups', {'add': [{
'name': 'Bar',
}]})
self.assert_([x for x in test.groups if x.name == 'Bar'])
test.groups.extend(Group.find())
group = test.groups[0]
test._on_change_set('groups', {'update': [{
'id': group.id,
'name': 'Foo',
}]})
self.assert_([x for x in test.groups if x.name == 'Foo'])
示例9: crear_company
def crear_company(config, lang):
""" Crear company. Traer datos de AFIP"""
Currency = Model.get('currency.currency')
Company = Model.get('company.company')
Party = Model.get('party.party')
# crear company
# obtener nombre de la compania de un archivo.
print u'\n>>> creando company...'
import ConfigParser
ini_config = ConfigParser.ConfigParser()
ini_config.read('company.ini')
currencies = Currency.find([('code', '=', 'ARS')])
currency, = currencies
company_config = Wizard('company.company.config')
company_config.execute('company')
company = company_config.form
party = Party(name='NOMBRE COMPANY')
party.lang = lang
party.vat_country = 'AR'
try:
party.vat_number = ini_config.get('company', 'cuit')
party.iva_condition = ini_config.get('company', 'iva_condition')
except Exception,e:
print 'Error: No se ha configurado correctamente company.ini\n'
raise SystemExit(repr(e))
示例10: create_chart
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
示例11: crear_account_invoice_ar_pos
def crear_account_invoice_ar_pos(config, lang):
""" Crear Punto de Venta Electronico con Factura A, B y C """
print u'\n>>> Comienza creacion de POS Electronico para Facturas A, B y C'
Company = Model.get('company.company')
Pos = Model.get('account.pos')
PosSequence = Model.get('account.pos.sequence')
company, = Company.find([])
punto_de_venta = Pos()
punto_de_venta.pos_type = 'electronic'
punto_de_venta.number = 2
punto_de_venta.pyafipws_electronic_invoice_service = 'wsfe'
punto_de_venta.save()
facturas = {
'1': '01-Factura A',
'6': '06-Factura B',
'11': '11-Factura C'
}
for key, name in facturas.iteritems():
print u'\n>>> Creamos POS para '+name
pos_sequence = PosSequence()
pos_sequence.invoice_type = key
pos_sequence.invoice_sequence = _crear_seq(config, name, company)
pos_sequence.pos = punto_de_venta
pos_sequence.save()
示例12: test_class_cache
def test_class_cache(self):
User1 = Model.get('res.user')
User2 = Model.get('res.user')
self.assertEqual(id(User1), id(User2))
Model.reset()
User3 = Model.get('res.user')
self.assertNotEqual(id(User1), id(User3))
示例13: test_translation_export
def test_translation_export(self):
Lang = Model.get('ir.lang')
Module = Model.get('ir.module.module')
translation_export = Wizard('ir.translation.export')
translation_export.form.language, = Lang.find([('code', '=', 'en_US')])
translation_export.form.module, = Module.find([('name', '=', 'ir')])
translation_export.execute('export')
self.assert_(translation_export.form.file)
translation_export.execute('end')
示例14: test_reference
def test_reference(self):
Attachment = Model.get('ir.attachment')
User = Model.get('res.user')
admin = User.find([('login', '=', 'admin')])[0]
attachment = Attachment()
attachment.name = 'Test'
attachment.resource = admin
attachment.save()
self.assertEqual(attachment.resource, admin)
示例15: check_category
def check_category(cat_name, simulate):
cats = Model.get('product.category').find([("name", "=", cat_name)])
if not cats:
if not simulate:
cat = Model.get('product.category')()
cat.name = cat_name
cat.save()
return cat
return None
return cats[0]