Tryton ERP Development: Part 3

  • Tutorial
Work with modules of the company (company), counterparties (party), goods (product) and warehouse (stock).


Part 1: Install tryotnd, query structure, work with the database
Part 2: Method structure, work with users and groups, install modules
Part 3: Work with company modules, partners, parties, products (product) and warehouse (stock )

1. An example of installing modules


As the first iteration, we were tasked with ensuring the operation of the warehouse. So let's install the appropriate module.

After downloading and unpacking the stock module, you cannot install it, because for the module to work, you need to install the dependencies. To get a list of module dependencies, there is a method ir.module.dependencies, but it returns one unsolved dependency; I did not manage to get a list of the required modules through this method right away.

Method model.ir.module.module.readreturns a fielddependencies, but there is only the id of the necessary modules. You can again use these methods to get the names of these modules. Although it will be easier to open tryton.cfg, which is located in the root of the module and in the depends section, to see the necessary modules. For the warehouse, this is company, currency, ir, party, product. The party module also has company dependencies. Download and install the necessary modules.

After installation, it system.server.listMethodsreturns 625 more methods in the model class. Below is a schematic representation of the new methods:



Now consider these methods in more detail.

2. API for working with modules



All classes have 6 main methods: create, delete, fields_get, search, read, write. Below I will describe them for the main classes of modules.
2.1. Company module API

Method nameParametersDescription
model.company.company.search[user_id, cookie, [], start, end, null, {}]Returns a slice of the id list of existing companies (id [start: end]).
model.company.company.fields_get[user_id, cookie, [], {}]Returns a list of the fields the company has.
model.company.company.read[user_id, cookie, list_of_company_ids, list_of_field_names, {}]Returns the values ​​of the specified fields of the specified companies.
model.company.company.create[user_id, cookie, [{field_name: field_data, field_name: field_data, ...}], {}]Create a company, at least you need to set the name field.
model.company.company.delete[user_id, cookie, list_delete_company_ids, {}]Deletes users by id.
model.company.company.write[user_id, cookie, list_update_company_ids, [{field_name: field_data, field_name: field_data, ...}], {}]Changes user field values ​​by id.


The company module has a minor employee class that allows you to create employees. To appoint employees, you need to change the employer field of the company.

2.2. Party module API (counterparties)


Method nameParametersDescription
model.party.party.search[user_id, cookie, [], start, end, null, {}]Returns a slice of the id list of existing contractors (id [start: end]).
model.party.party.fields_get[user_id, cookie, [], {}]Returns a list of fields available to the counterparty.
model.party.party.read[user_id, cookie, list_of_party_ids, list_of_field_names, {}]Returns the values ​​of the specified fields of the specified counterparties.
model.party.party.create[user_id, cookie, [{field_name: field_data, field_name: field_data, ...}], {}]Create a counterparty, at least you need to set the name field.
model.party.party.delete[user_id, cookie, list_delete_party_ids, {}]Deletes counterparties by id.
model.party.party.write[user_id, cookie, list_update_party_ids, [{field_name: field_data, field_name: field_data, ...}], {}]Changes the values ​​of counterparty fields by id.


The counterparty module has a secondary class address, which allows you to create addresses and assign them to counterparties. The same class is used in the warehouse module.

2.3. Product module API

Method nameParametersDescription
model.product.product.search[user_id, cookie, [], start, end, null, {}]Returns a slice of the id list of existing products (id [start: end]).
model.product.product.fields_get[user_id, cookie, [], {}]Returns a list of fields available for the product.
model.product.product.read[user_id, cookie, list_of_product_ids, list_of_field_names, {}]Returns the values ​​of the specified fields of the specified products.
model.product.product.create[user_id, cookie, [{field_name: field_data, field_name: field_data, ...}], {}]To create a product, at least you need to set the field name, list_price, cost_price, default_uom.
model.product.product.delete[user_id, cookie, list_delete_product_ids, {}]Deletes products by id.
model.product.product.write[user_id, cookie, list_update_product_ids, [{field_name: field_data, field_name: field_data, ...}], {}]Changes the values ​​of product fields by id.


There are also similar methods product.templatethat do the same thing as product.product.
It is also necessary to pay attention to the required field default_uom, which indicates the unit of measurement of the goods. For work with units of measure the class is used product.uom. Accordingly, in order to get a list of available units of measurement, you can use the methods model.product.uom.search, model.product.uom.read.

List id with uom names
idTitle
1Thing
2Kilogram
3Gram
4Carat
5Lb
6Ounce
7Second
8Minute
9Hour
10Working day
elevenDay
12Meter
thirteenKilometer
14centimeter
fifteenMillimeter
16Foot
17Yard
18Inch
19Mile
20Cubic meter
21Liter
22Cubic centimeter
23Cubic inch
24Cubic foot
25Gallon
26Square meter
27Square centimeter
28Ar
29thHectare
thirtySquare inch
31Square foot
32Square yard



An example of how to get existing units
import json
import requests
url = 'http://localhost:8000/try'
id = 1
methodname = 'common.server.login'
params = ('test', 'test')
request = json.dumps({
                'id': id,
                'method': methodname,
                'params': params,
                })
r = requests.post(url, data=request)
user_id, cookie = r.json()['result']
print user_id, cookie
id = 2
methodname = 'model.product.uom.search'
params = [user_id, cookie, [], 0, 1000, None, {}]
request = json.dumps({
                'id': id,
                'method': methodname,
                'params': params,
                })
r = requests.post(url, data=request)
print request
uom= r.json()['result']
id = 4
methodname = 'model.product.uom.read'
params = (user_id, cookie, uom, ['name'], {})
request = json.dumps({
                'id': id,
                'method': methodname,
                'params': params,
                })
r = requests.post(url, data=request)
print r.json()['result']



2.4. Category API

For all main classes, you can create hierarchical categorization. To create a hierarchy, the parent field is used, which indicates the id of the parent.

Method nameParametersDescription
model. *. category.search[user_id, cookie, [], start, end, null, {}]Returns a slice of the id list of existing categories (id [start: end]).
model. *. category.fields_get[user_id, cookie, [], {}]Returns a list of the fields available for the category.
model. *. category.read[user_id, cookie, list_of_category_ids, list_of_field_names, {}]Returns the values ​​of the specified fields of the specified categories.
model. *. category.create[user_id, cookie, [{field_name: field_data, field_name: field_data, ...}], {}]Create a category, at least you need to set the name field.
model. *. category.delete[user_id, cookie, list_delete_category_ids, {}]Deletes categories by id.
model. *. category.write[user_id, cookie, list_update_category_ids, [{field_name: field_data, field_name: field_data, ...}], {}]Changes the values ​​of category fields by id.


2.5. Stock module API (warehouse)

It took a lot of time to understand that you need to use any user other than admin to work with warehouse documents, and besides, you must bind it to the company (specify the company field), otherwise you will receive a UserError in response.

The warehouse module has 5 types of documents:
  1. stock.shipment.in - a document of delivery of goods to the warehouse from the supplier.
  2. stock.shipment.in.return - document returning goods to the supplier.
  3. stock.shipment.internal - document of internal movement between warehouses.
  4. stock.shipment.out - document of shipment of goods from the warehouse to the buyer.
  5. stock.shipment.out.return - return document from the buyer.


Below is a diagram for a clear understanding of the movement of goods in warehouses:



For several physical warehouses, you must either duplicate the warehouse with the zones of delivery and shipment, or make several storage zones.

Below is the API for working with warehouse documents; instead of an asterisk, we substitute the class of the required document, for example model.stock.shipment.in.search.

Method nameParametersDescription
model. *. search[user_id, cookie, [], start, end, null, {}]Returns a slice of the id list of existing documents (id [start: end]).
model. *. fields_get[user_id, cookie, [], {}]Returns a list of fields available for documents.
model. *. read[user_id, cookie, list_of_shipment_ids, list_of_field_names, {}]Returns the values ​​of the specified fields of the specified documents.
model. *. create[user_id, cookie, [{field_name: field_data, field_name: field_data, ...}], {}]Create a document.
model. *. delete[user_id, cookie, list_delete_shipment_ids, {}]Deletes the document by id.
model. *. write[user_id, cookie, list_update_shipment_ids, [{field_name: field_data, field_name: field_data, ...}], {}]Changes the values ​​of document fields by id.
model. *. wait[user_id, cookie, list_shipment_ids, {}]Changes the state of a document pending by id.
model. *. done[user_id, cookie, list_shipment_ids, {}]Changes the state of a document to id.


The warehouse module has a secondary location class for working directly with warehouses, rather than the movement of goods across warehouses and zones.

Here is an example of parameters for the model.stock.shipment.in.create method [user_id, cookie, [{"company": 1, "incoming_moves": [["create", [{"to_location": 1, "product": 1, "from_location": 5, "company": 1, "unit_price": {"decimal": "12.000", "__class__": "Decimal"}, "currency": 123, "uom": 2, "quantity": 90.0}]]], "warehouse": 4, "supplier": 1}], {}]. Pay attention to “unit_price”: {“decimal”: “12.000”, “__class__”: “Decimal”}, if you set “unit_price”: 12.000 in the request, the request will not be executed, because the warehouse module will not be able to convert the number it needs to the Decimal class. This behavior is seen only in the fields that are responsible for the price.

Delivery documents stock.shipment.in have two states - draft (draft), done. The remaining documents have three states - draft (draft), wait (waiting), done (completed). The status of documents affects reports on balances of goods and warehouses. If the document has draft status, then the product indicated in it is not displayed in reports. If the document is in the wait state, then in the reports the goods are in the warehouse from which the transfer / shipment is made. If the document is in the done state, then the goods in the report are in the warehouse to which the transfer / shipment is made.

The warehouse module has a report of the balance of products in a specific warehouse / supply-shipment area - wizard.stock.products_by_locations. The main wizard class is used to get reports. Using the create method, a database query is created and written to the database, the execute method executes the query and the result is written to the database, the delete method removes the query and the results of its execution from the database.

Method nameParametersDescription
wizard.stock.products_by_locations.create[user_id, cookie, [], {}]Creates a query for a report on products in stock. The method returns the id of the report.
wizard.stock.products_by_locations.execute[user_id, cookie, wizard_id, {"start": {"forecast_date": {"month": number_of_month, "__class__": "date", "day": number_of_day, "year": number_of_year}}}, "open" , {"Active_id": warehouse_id, "active_model": "stock.location", "active_ids": [warehouse_ids]}]Fulfills the request. You must specify the date on which the calculation of the balances and the warehouse id will be made.
wizard.stock.products_by_locations.delete[user_id, cookie, wizard_id, {}]Deletes the report by id.

Also popular now: