# NotImplementedError: Missing setter function for field "Cost Price" in "Product Template"

**URL:** https://discuss.tryton.org/t/notimplementederror-missing-setter-function-for-field-cost-price-in-product-template/3940
**Category:** Developer
**Created:** [March 15, 2021, 10:22am UTC](https://discuss.tryton.org/t/notimplementederror-missing-setter-function-for-field-cost-price-in-product-template/3940 "2021-03-15T10:22:29Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![deathrake](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/d/b487fb/32.png) [@deathrake](https://discuss.tryton.org/u/deathrake)
#### Post date: [March 15, 2021, 10:22am UTC](https://discuss.tryton.org/t/notimplementederror-missing-setter-function-for-field-cost-price-in-product-template/3940/1 "2021-03-15T10:22:29Z")

</div>

python flask api code

```
@product_api.route("/addproduct" , methods=['POST'])
@tryton.transaction()
def addproduct():
       ProductTemplate.create([{'name': productname , 'type': type,'consumable':consumable, 'purchasable': purchasable , 'salable':salable , 'cost_price_method' : cost_price_method , 'cost_price' : cost_price , 'list_price': list_price , 'default_uom': 2 }])

```

product.template model

```
cost_price = fields.Function(fields.Numeric( "Cost Price", digits=price_digits,help="The amount it costs to purchase or make the product, " "or carry out the service."),'get_cost_price')

products = fields.One2Many( 'product.product', 'template', "Variants",help="The different variants the product comes in.")

def get_cost_price(self, name):

        if len(self.products) == 1:

            product, = self.products

            return product.cost_price

```

how can i use setter function in tha tryton flask api ?

---

<div class="post-metadata">

### Author: ![pokoli](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/pokoli/32/22_2.png) [@pokoli](https://discuss.tryton.org/u/pokoli)
#### Post date: [March 15, 2021, 11:25am UTC](https://discuss.tryton.org/t/notimplementederror-missing-setter-function-for-field-cost-price-in-product-template/3940/2 "2021-03-15T11:25:17Z")

</div>

The problem is that you added a cost\_price functional field on template (and you are setting the cost\_price on your create call) but you did not implement any `setter` method for the field.

There are two solutions to fix the error:

1. Create a setter function to store the cost price on the variant
2. Remove the `cost_price` key from the create call so the value is not set.

Hope this helps!

---

<div class="post-metadata">

### Author: ![deathrake](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/d/b487fb/32.png) [@deathrake](https://discuss.tryton.org/u/deathrake)
#### Post date: [March 15, 2021, 11:38am UTC](https://discuss.tryton.org/t/notimplementederror-missing-setter-function-for-field-cost-price-in-product-template/3940/3 "2021-03-15T11:38:17Z")

</div>

any example of creating a setter function do i need to create it in flask ?

an example woulld be greatly appreciated

---

<div class="post-metadata">

### Author: ![deathrake](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/d/b487fb/32.png) [@deathrake](https://discuss.tryton.org/u/deathrake)
#### Post date: [March 15, 2021, 11:40am UTC](https://discuss.tryton.org/t/notimplementederror-missing-setter-function-for-field-cost-price-in-product-template/3940/4 "2021-03-15T11:40:54Z")

</div>

by creating a setter function . do you mean to implement a function that would set variant in product.product ?

---

<div class="post-metadata">

### Author: ![pokoli](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/pokoli/32/22_2.png) [@pokoli](https://discuss.tryton.org/u/pokoli)
#### Post date: [March 15, 2021, 2:54pm UTC](https://discuss.tryton.org/t/notimplementederror-missing-setter-function-for-field-cost-price-in-product-template/3940/5 "2021-03-15T14:54:14Z")

</div>

I meant implementing a function that implements the [setter API](https://docs.tryton.org/projects/server/en/latest/ref/models/fields.html?highlight=setter#trytond.model.fields.Function.setter)

If you search for setter on the source code of tryton there are a lot of examples.
