feat: issue OneTeam/Naliia_Dev#5
This commit is contained in:
81
demo/company.py
Normal file
81
demo/company.py
Normal file
@@ -0,0 +1,81 @@
|
||||
import datetime as dt
|
||||
from decimal import Decimal
|
||||
|
||||
from proteus import Model, Wizard
|
||||
|
||||
from tools import open_file
|
||||
|
||||
dir = "./demo/data"
|
||||
file_ = "party_company.csv"
|
||||
path = "".join([dir, "/", file_])
|
||||
|
||||
|
||||
def setup(config, modules, company_config):
|
||||
data, = open_file(path)
|
||||
|
||||
Address = Model.get('party.address')
|
||||
Company = Model.get('company.company')
|
||||
Country = Model.get('country.country')
|
||||
Currency = Model.get('currency.currency')
|
||||
Party = Model.get('party.party')
|
||||
Subdivision = Model.get('country.subdivision')
|
||||
|
||||
company_currency, = Currency.find([
|
||||
('code', '=', company_config["company_currency"])
|
||||
])
|
||||
|
||||
rate = company_currency.rates.new()
|
||||
rate.date = dt.date(dt.date.today().year, 1, 1)
|
||||
rate.rate = Decimal('1')
|
||||
|
||||
company_currency.save()
|
||||
|
||||
try:
|
||||
company_country, = Country.find([('code', '=', company_config["company_country"])])
|
||||
except ValueError:
|
||||
company_country = None
|
||||
|
||||
|
||||
CompanyWizard = Wizard('company.company.config')
|
||||
CompanyWizard.execute('company')
|
||||
|
||||
company = CompanyWizard.form
|
||||
party = Party(name=data.get("name"))
|
||||
|
||||
address = Address()
|
||||
address.street = data.get("street")
|
||||
address.city = data.get("city")
|
||||
address.country = company_country
|
||||
|
||||
try:
|
||||
address.subdivision, = Subdivision.find([
|
||||
('code', '=', company_config["company_subdivision"])
|
||||
])
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
party.addresses.append(address)
|
||||
party.save()
|
||||
|
||||
company.party = party
|
||||
company.currency = company_currency
|
||||
company.timezone = company_config["company_timezone"]
|
||||
CompanyWizard.execute('add')
|
||||
|
||||
# Reload context
|
||||
User = Model.get('res.user')
|
||||
config._context = User.get_preferences(True, {})
|
||||
|
||||
company, = Company.find()
|
||||
|
||||
return company
|
||||
|
||||
|
||||
def get():
|
||||
|
||||
data, = open_file(path)
|
||||
Company = Model.get('company.company')
|
||||
|
||||
if company := Company.find([('party.name', '=', data.get("name"))]):
|
||||
return company
|
||||
return
|
||||
Reference in New Issue
Block a user