# AttributeError: 'sale.sale' Model has no attribute '\_save\_values'

**URL:** <https://discuss.tryton.org/t/attributeerror-sale-sale-model-has-no-attribute-save-values/7370>\
**Category:** Developer\
**Created:** [June 9, 2024, 12:32pm UTC](https://discuss.tryton.org/t/attributeerror-sale-sale-model-has-no-attribute-save-values/7370 "2024-06-09T12:32:52Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![lb1975](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/l/d6d6ee/32.png) [@lb1975](https://discuss.tryton.org/u/lb1975)\
**Post date:** [June 9, 2024, 12:32pm UTC](https://discuss.tryton.org/t/attributeerror-sale-sale-model-has-no-attribute-save-values/7370/1 "2024-06-09T12:32:53Z")

</div>

Hi,

I get some code from opportunity.py to create dynamically a sale from a trade but when I try to save I get the error mentionned in the title.

```auto
def get_sale_line(self, sale):
    SaleLine = Pool().get('sale.line')
    sale_line = SaleLine(
        type='line',
        product=None,
        sale=sale,
        description=None,
        )
    sale_line.quantity = self.position_quantity
    sale_line.unit = self.position_unit
    sale_line.unit_price = self.pricings[0].pricing_price
    return sale_line

def _get_sale(self):
    Sale = Pool().get('sale.sale')
    return Sale(
        description='test description',
        party=self.position_counterparty,
        contact=None,
        payment_term=self.position_payment_term,
        company=Transaction().context.get('company'),
        invoice_address='test address',
        shipment_address='test address',
        currency=self.pricings[0].pricing_curr.id,
        comment='test comment',
        sale_date=None,
        origin=self,
        warehouse=Sale.default_warehouse(),
        )

def create_sale(self):
    sale = self._get_sale()
    sale_lines = []
    sale_lines.append(self.get_sale_line(sale))
    sale.lines = sale_lines
    return sale

```

The error comes with this instruction:

```auto
sale = positions[0].create_sale()
Sale.save([sale])

```

Any ideas ?

Tks in advance.  
Laurent

---

<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:** [June 9, 2024, 12:43pm UTC](https://discuss.tryton.org/t/attributeerror-sale-sale-model-has-no-attribute-save-values/7370/2 "2024-06-09T12:43:38Z")

</div>

Without the proper traceback, it is difficult to help.

---

<div class="post-metadata">

**Author:** ![lb1975](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/l/d6d6ee/32.png) [@lb1975](https://discuss.tryton.org/u/lb1975)\
**Post date:** [June 9, 2024, 1:13pm UTC](https://discuss.tryton.org/t/attributeerror-sale-sale-model-has-no-attribute-save-values/7370/3 "2024-06-09T13:13:36Z")

</div>

```auto
Traceback (most recent call last):
  File "/trytond/model/model.py", line 390, in _getitem
    return getattr(self, field)
AttributeError: 'sale.sale._record' object has no attribute '_save_values'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/trytond/model/model.py", line 313, in __getattr__
    return self._values[name]
  File "/trytond/model/model.py", line 392, in _getitem
    raise KeyError(field)
KeyError: '_save_values'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/trytond/wsgi.py", line 109, in dispatch_request
    return endpoint(request, **request.view_args)
  File "/trytond/protocols/dispatcher.py", line 43, in rpc
    return methods.get(request.rpc_method, _dispatch)(
  File "/trytond/wsgi.py", line 75, in wrapper
    return func(request, *args, **kwargs)
  File "/trytond/protocols/wrappers.py", line 197, in wrapper
    return func(request, pool, *args, **kwargs)
  File "/trytond/protocols/dispatcher.py", line 204, in _dispatch
    result = rpc.result(meth(*c_args, **c_kwargs))
  File "/trytond/model/modelview.py", line 720, in wrapper
    return func(cls, records, *args, **kwargs)
  File "/trytond/model/workflow.py", line 37, in wrapper
    result = func(cls, filtered, *args, **kwargs)
  File "/trytond/modules/trade/position.py", line 238, in quote
    cls._process_invoice(positions)
  File "/trytond/modules/trade/position.py", line 287, in _process_invoice
    Sale.save([sale])
  File "/trytond/model/descriptors.py", line 33, in newfunc
    return self.func(owner, *args, **kwargs)
  File "/trytond/model/modelstorage.py", line 1947, in save
    save_values[record] = record._save_values
  File "/trytond/model/modelstorage.py", line 1608, in __getattr__
    return super(ModelStorage, self). __getattr__ (name)
  File "/trytond/model/model.py", line 315, in __getattr__
    raise AttributeError("'%s' Model has no attribute '%s': %s"
AttributeError: 'sale.sale' Model has no attribute '_save_values': <trytond.model.model.sale.sale._record object at 0x7f82b4b8a040>

```

---

<div class="post-metadata">

**Author:** ![lb1975](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/l/d6d6ee/32.png) [@lb1975](https://discuss.tryton.org/u/lb1975)\
**Post date:** [June 9, 2024, 1:21pm UTC](https://discuss.tryton.org/t/attributeerror-sale-sale-model-has-no-attribute-save-values/7370/4 "2024-06-09T13:21:44Z")

</div>

In fact first I wanted to create account.invoice from my trade module to connect with Tryton module. I had this error for account.invoice when trying to save. So I decided to generate a sale to use the method of Tryton to generate the invoice but now the error is on sale.sale

---

<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:** [June 9, 2024, 1:22pm UTC](https://discuss.tryton.org/t/attributeerror-sale-sale-model-has-no-attribute-save-values/7370/5 "2024-06-09T13:22:06Z")

</div>

An `AttributeError` must be raised in `ModelStorage._save_values` which is hidden by the `property` decorator. It is probably a wrong type for a field or something like that.

_We should not have used a property for this attribute: [Replace \_save\_values and \_changed\_values property by method call (#13317) · Issues · Tryton / Tryton · GitLab](https://bugs.tryton.org/13317)_

---

<div class="post-metadata">

**Author:** ![lb1975](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/l/d6d6ee/32.png) [@lb1975](https://discuss.tryton.org/u/lb1975)\
**Post date:** [June 9, 2024, 1:23pm UTC](https://discuss.tryton.org/t/attributeerror-sale-sale-model-has-no-attribute-save-values/7370/6 "2024-06-09T13:23:03Z")

</div>

Ok tks I’ll investigate field side

---

<div class="post-metadata">

**Author:** ![lb1975](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/l/d6d6ee/32.png) [@lb1975](https://discuss.tryton.org/u/lb1975)\
**Post date:** [June 9, 2024, 1:31pm UTC](https://discuss.tryton.org/t/attributeerror-sale-sale-model-has-no-attribute-save-values/7370/7 "2024-06-09T13:31:43Z")

</div>

Yes it was a problem of field type invoice\_address well done Cédric, the error message misled me
