# Automatically loading company, party and product records for testing

**URL:** <https://discuss.tryton.org/t/automatically-loading-company-party-and-product-records-for-testing/4174>\
**Category:** Developer\
**Created:** [May 9, 2021, 4:56pm UTC](https://discuss.tryton.org/t/automatically-loading-company-party-and-product-records-for-testing/4174 "2021-05-09T16:56:28Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)\
**Post date:** [July 31, 2023, 11:07am UTC](https://discuss.tryton.org/t/automatically-loading-company-party-and-product-records-for-testing/4174/21 "2023-07-31T11:07:51Z")

</div>

They come from the `country` and `currency` modules.

---

<div class="post-metadata">

**Author:** ![dortizmunoz](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/d/a88e4f/32.png) [@dortizmunoz](https://discuss.tryton.org/u/dortizmunoz)\
**Post date:** [July 31, 2023, 11:31am UTC](https://discuss.tryton.org/t/automatically-loading-company-party-and-product-records-for-testing/4174/22 "2023-07-31T11:31:51Z")

</div>

Do you mean download them from here?:  
[https://hg.tryton.org/modules](https://hg.tryton.org/modules)

---

<div class="post-metadata">

**Author:** ![acaubet](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/acaubet/32/1493_2.png) [@acaubet](https://discuss.tryton.org/u/acaubet)\
**Post date:** [July 31, 2023, 11:50am UTC](https://discuss.tryton.org/t/automatically-loading-company-party-and-product-records-for-testing/4174/23 "2023-07-31T11:50:15Z")

</div>

You can do the importing from the console commands documented:  
[Loading and updating countries and subdivisions](https://docs.tryton.org/projects/modules-country/en/latest/setup.html#loading-and-updating-countries-and-subdivisions)  
[Loading and updating currencies](https://docs.tryton.org/projects/modules-currency/en/latest/setup.html#loading-and-updating-currencies)

Also you can incorporate the loading of those scripts in the demo script with some function like the `load_zips` showed in [my talk on TUB2023 at 27:43](https://www.youtube.com/live/dS3VFMhrG2Y?feature=share&t=1663) minute.

---

<div class="post-metadata">

**Author:** ![edbo](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/e/f14d63/32.png) [@edbo](https://discuss.tryton.org/u/edbo)\
**Post date:** [July 31, 2023, 11:54am UTC](https://discuss.tryton.org/t/automatically-loading-company-party-and-product-records-for-testing/4174/24 "2023-07-31T11:54:52Z")

</div>

> [@dortizmunoz](#):
>
> Do you mean download them from here?:

No, this not needed, the scripts are coming with the modules itself. When you install the `country` and `currency` module, those scripts should be callable from the command line using the provided information @acaubet provided.

---

<div class="post-metadata">

**Author:** ![dortizmunoz](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/d/a88e4f/32.png) [@dortizmunoz](https://discuss.tryton.org/u/dortizmunoz)\
**Post date:** [July 31, 2023, 11:57am UTC](https://discuss.tryton.org/t/automatically-loading-company-party-and-product-records-for-testing/4174/25 "2023-07-31T11:57:05Z")

</div>

Thanks for answering both of you.  
From the command line and trying one of them I get this error:

```auto
File "/home/npc/.local/bin/trytond_import_countries", line 5, in <module>
    from trytond.modules.country.scripts.import_countries import run
  File "/home/npc/.local/lib/python3.8/site-packages/trytond/modules/country/scripts/import_countries.py", line 12, in <module>
    import pycountry
ModuleNotFoundError: No module named 'pycountry'

```

---

<div class="post-metadata">

**Author:** ![edbo](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/e/f14d63/32.png) [@edbo](https://discuss.tryton.org/u/edbo)\
**Post date:** [July 31, 2023, 12:30pm UTC](https://discuss.tryton.org/t/automatically-loading-company-party-and-product-records-for-testing/4174/26 "2023-07-31T12:30:11Z")

</div>

That’s a missing dependency, just install it. I think you will get more of these.

---

<div class="post-metadata">

**Author:** ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)\
**Post date:** [July 31, 2023, 12:32pm UTC](https://discuss.tryton.org/t/automatically-loading-company-party-and-product-records-for-testing/4174/27 "2023-07-31T12:32:31Z")

</div>

Indeed it is not necessary since [Sign in · GitLab](https://foss.heptapod.net/tryton/tools/-/commit/f403c9f8b2c7)  
But of course pycountry package must be installed.

---

<div class="post-metadata">

**Author:** ![dortizmunoz](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/d/a88e4f/32.png) [@dortizmunoz](https://discuss.tryton.org/u/dortizmunoz)\
**Post date:** [July 31, 2023, 2:50pm UTC](https://discuss.tryton.org/t/automatically-loading-company-party-and-product-records-for-testing/4174/28 "2023-07-31T14:50:24Z")

</div>

After installing pycountry with the instruction:  
$ sudo apt-get install python3-pycountry

And try again to import the data, now I get the following error:

```auto
/usr/lib/python3/dist-packages/apport/report.py:13: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
  import fnmatch, glob, traceback, errno, sys, atexit, imp, stat
Traceback (most recent call last):
  File "tryton_demo.py", line 1014, in <module>
    main(options.database, options.modules, options.demo_password,
  File "tryton_demo.py", line 933, in main
    customers, suppliers = setup_party(config, modules)
  File "tryton_demo.py", line 71, in setup_party
    us, = Country.find([('code', '=', 'US')])
ValueError: not enough values to unpack (expected 1, got 0)

```

---

<div class="post-metadata">

**Author:** ![edbo](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/e/f14d63/32.png) [@edbo](https://discuss.tryton.org/u/edbo)\
**Post date:** [July 31, 2023, 3:28pm UTC](https://discuss.tryton.org/t/automatically-loading-company-party-and-product-records-for-testing/4174/29 "2023-07-31T15:28:02Z")

</div>

Did you run the `trytond_import_countries` script?

Looking at [Sign in · GitLab](https://foss.heptapod.net/tryton/tools/-/blob/4dbc09c5392f5dd6feafccb41f214be26f2b1807/tryton_demo.py#L990), did you provide the `country` module to the arguments? The `country` module is not added by default.

---

<div class="post-metadata">

**Author:** ![dortizmunoz](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/d/a88e4f/32.png) [@dortizmunoz](https://discuss.tryton.org/u/dortizmunoz)\
**Post date:** [July 31, 2023, 4:01pm UTC](https://discuss.tryton.org/t/automatically-loading-company-party-and-product-records-for-testing/4174/30 "2023-07-31T16:01:28Z")

</div>

Thanks friends, we are getting closer.  
After installing the countries and currencies, I now get this error:

```auto
/usr/lib/python3/dist-packages/apport/report.py:13: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
  import fnmatch, glob, traceback, errno, sys, atexit, imp, stat
Traceback (most recent call last):
  File "tryton_demo.py", line 122, in setup_party
    party, = Party.find([('name', '=', name)])
ValueError: not enough values to unpack (expected 1, got 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "tryton_demo.py", line 1014, in <module>
    main(options.database, options.modules, options.demo_password,
  File "tryton_demo.py", line 933, in main
    customers, suppliers = setup_party(config, modules)
  File "tryton_demo.py", line 126, in setup_party
    party.avatar = get_avatar('saber.jpg')
  File "tryton_demo.py", line 21, in get_avatar
    with open(os.path.join(AVATAR_DIR, name), 'rb') as fp:
FileNotFoundError: [Errno 2] No such file or directory: 'avatars/saber.jpg'

```

---

<div class="post-metadata">

**Author:** ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)\
**Post date:** [July 31, 2023, 4:03pm UTC](https://discuss.tryton.org/t/automatically-loading-company-party-and-product-records-for-testing/4174/31 "2023-07-31T16:03:18Z")

</div>

Ha yes the script except to find some pictures in an `avatars` directory if you activate the `party_avatar` module.

---

<div class="post-metadata">

**Author:** ![dortizmunoz](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/d/a88e4f/32.png) [@dortizmunoz](https://discuss.tryton.org/u/dortizmunoz)\
**Post date:** [July 31, 2023, 4:21pm UTC](https://discuss.tryton.org/t/automatically-loading-company-party-and-product-records-for-testing/4174/32 "2023-07-31T16:21:55Z")

</div>

I’m sorry for so many questions, but there are many unknowns.

after install “$ pip install trytond-party-avatar”, I keep getting the error.

---

<div class="post-metadata">

**Author:** ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)\
**Post date:** [July 31, 2023, 4:51pm UTC](https://discuss.tryton.org/t/automatically-loading-company-party-and-product-records-for-testing/4174/33 "2023-07-31T16:51:08Z")

</div>

As I said if you activate `party_avatar` module then the script expect to find avatars in the `avatars` directory. So you must create such directory and fill it if you activate the module.

_Again this script is really not for new comers, it is an internal tool to build our demo service._

---

<div class="post-metadata">

**Author:** ![dortizmunoz](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/d/a88e4f/32.png) [@dortizmunoz](https://discuss.tryton.org/u/dortizmunoz)\
**Post date:** [July 31, 2023, 10:19pm UTC](https://discuss.tryton.org/t/automatically-loading-company-party-and-product-records-for-testing/4174/34 "2023-07-31T22:19:52Z")

</div>

Okay, but is there any way to know where the directory is created and if you have content to be able to dump it or just leave it? Since there is nothing 100% automated to be able to test with sample data?

This would really help the community a lot so that people who don’t know the software would be interested in having it. On the other hand, if there is not something automated where people can see that data, it will be more difficult for people to continue.

Thank you

---

<div class="post-metadata">

**Author:** ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)\
**Post date:** [July 31, 2023, 10:49pm UTC](https://discuss.tryton.org/t/automatically-loading-company-party-and-product-records-for-testing/4174/35 "2023-07-31T22:49:28Z")

</div>

> [@dortizmunoz](#):
>
> Okay, but is there any way to know where the directory is created and if you have content to be able to dump it or just leave it?

I put my folder on [https://www.tryton.org/~demo/avatars/](https://www.tryton.org/~demo/avatars/)

> [@dortizmunoz](#):
>
> Since there is nothing 100% automated to be able to test with sample data?

As I said earlier, there is [https://www.tryton.org/~demo/](https://www.tryton.org/~demo/)

---

<div class="post-metadata">

**Author:** ![dortizmunoz](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/d/a88e4f/32.png) [@dortizmunoz](https://discuss.tryton.org/u/dortizmunoz)\
**Post date:** [August 1, 2023, 8:37am UTC](https://discuss.tryton.org/t/automatically-loading-company-party-and-product-records-for-testing/4174/36 "2023-08-01T08:37:27Z")

</div>

Despite everything, I continue with the process.  
Now I get this error, I understand that it may be some company data that is missing too, right?

```auto
 File "tryton_demo.py", line 1014, in <module>
    main(options.database, options.modules, options.demo_password,
  File "tryton_demo.py", line 939, in main
    company, = Company.find([
ValueError: not enough values to unpack (expected 1, got 0)

```

---

<div class="post-metadata">

**Author:** ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)\
**Post date:** [August 1, 2023, 9:19am UTC](https://discuss.tryton.org/t/automatically-loading-company-party-and-product-records-for-testing/4174/37 "2023-08-01T09:19:31Z")

</div>

I guess you are running multiple times the script on the same database and some run has failed at some point. So the data are inconsistent for the script (which can not use transaction).  
If the script fails at any time, you must restart the process with a clean database.

---

<div class="post-metadata">

**Author:** ![dortizmunoz](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/d/a88e4f/32.png) [@dortizmunoz](https://discuss.tryton.org/u/dortizmunoz)\
**Post date:** [August 1, 2023, 10:02am UTC](https://discuss.tryton.org/t/automatically-loading-company-party-and-product-records-for-testing/4174/38 "2023-08-01T10:02:42Z")

</div>

I have deleted the Database and recreated it.

It goes through here and then gives this error:  
Update countries  
Update subdivisions  
Update subdivisions parent  
Update currencies

```auto
  File "tryton_demo.py", line 1014, in <module>
    main(options.database, options.modules, options.demo_password,
  File "tryton_demo.py", line 946, in main
    setup_account(config, activated, company)
  File "tryton_demo.py", line 252, in setup_account
    root_template, = AccountTemplate.find([
  ValueError: not enough values to unpack (expected 1, got 0)

```

---

<div class="post-metadata">

**Author:** ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)\
**Post date:** [August 1, 2023, 10:05am UTC](https://discuss.tryton.org/t/automatically-loading-company-party-and-product-records-for-testing/4174/39 "2023-08-01T10:05:36Z")

</div>

You should give which command line options you are using.  
But also which version of each packages and which configuration.

---

<div class="post-metadata">

**Author:** ![dortizmunoz](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/d/a88e4f/32.png) [@dortizmunoz](https://discuss.tryton.org/u/dortizmunoz)\
**Post date:** [August 1, 2023, 10:13am UTC](https://discuss.tryton.org/t/automatically-loading-company-party-and-product-records-for-testing/4174/40 "2023-08-01T10:13:25Z")

</div>

I am dumping the file: “tryton\_demo.py”

$ python3 tryton\_demo.py -c /etc/tryton/trytond.conf -d

Is this what you mean ced?

[Previous page](https://discuss.tryton.org/t/automatically-loading-company-party-and-product-records-for-testing/4174.md?page=1)

[Next page](https://discuss.tryton.org/t/automatically-loading-company-party-and-product-records-for-testing/4174.md?page=3)
