feat: Add Populate Scripts
This commit is contained in:
		
							
								
								
									
										98
									
								
								demo/populate_scripts/company.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										98
									
								
								demo/populate_scripts/company.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,98 @@ | ||||
| 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): | ||||
|  | ||||
|     Identifier = Model.get('party.identifier') | ||||
|     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 | ||||
|  | ||||
|     try: | ||||
|         company_subdivision, = Subdivision.find( | ||||
|             [('code', '=', company_config["company_subdivision"])] | ||||
|         ) | ||||
|     except ValueError: | ||||
|         company_subdivision = None | ||||
|  | ||||
|     try: | ||||
|         company_municipality, = Subdivision.find( | ||||
|             [('code', '=', company_config["company_municipality"])] | ||||
|         ) | ||||
|     except ValueError: | ||||
|         company_municipality = None | ||||
|  | ||||
|     CompanyWizard = Wizard('company.company.config') | ||||
|     CompanyWizard.execute('company') | ||||
|  | ||||
|     company = CompanyWizard.form | ||||
|     party = Party( | ||||
|         name=company_config["company_name"], | ||||
|         type_person=company_config["type_person"] | ||||
|     ) | ||||
|  | ||||
|     identifier = Identifier() | ||||
|     identifier.type = company_config["company_identifier_type"] | ||||
|     identifier.code = company_config["company_identifier"] | ||||
|  | ||||
|     party.identifiers.append(identifier) | ||||
|  | ||||
|     address = party.addresses[0] | ||||
|     address.street = company_config["company_street"] | ||||
|     address.country = company_country | ||||
|     address.subdivision = company_subdivision | ||||
|     address.subdivision_municipality = company_municipality | ||||
|  | ||||
|     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(company_config): | ||||
|  | ||||
|     Company = Model.get('company.company') | ||||
|  | ||||
|     if company := Company.find([ | ||||
|         ('party.name', '=', company_config["company_name"]) | ||||
|     ]): | ||||
|         return company | ||||
|     return | ||||
		Reference in New Issue
	
	Block a user