AttributeError: 'sale.sale' Model has no attribute '_save_values'

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.

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:

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

Any ideas ?

Tks in advance.
Laurent

Without the proper traceback, it is difficult to help.

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>

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

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

1 Like

Ok tks I’ll investigate field side

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