Odoo Help

2

0
20 Answers
1
Avatar

Temur Georgia

--Temur--

3375
| 7 5 9
Tbilisi, Georgia
--Temur--
Programmer
Temur Georgia
1/13/16, 7:40 AM

Try it please:

....
    goede_btw_id = btw_categ_pool.search(cr, uid, [('description','=','VAT-OUT-21-S')])
    if type(goede_btw_id) in (long, int,):
        browse_ids = [goede_btw_id]
    else:
        browse_ids = goede_btw_id
    for godie_btw_obj in btw_categ_pool.browse(cr, uid, browse_ids, context=context):
        if not goede_btw_obj.name:
            goede_btw_obj.name = goede_btw_obj.description
    result.update({'car_name': car_name,'car_license_plate': car_license_plate, 'car_mavirent_nummer': car_mavirent_nummer, 'car_chassis': car_chassis, 'car_rent_price': car_rent_price, 'car_number_of_units': car_number_of_units, 'car_line_tax_id': [(6, 0, goede_btw_id)]})
....


UPDATE:

'account' is in dependency list, but I've got "IntegrityError: null value in column "name" violates not-null constraint" anyway. this error were originated from missing mandatory field "name" in "account_analytic_invoice_line" object, I fixed it in place by replacing required=True to required=False... I.e. if it meant not to be required, it should be fixed as follows:


class account_analytic_invoice_line(models.Model):
    _inherit = "account.analytic.invoice.line"

name = fields.Text(required=False) 

this way "IntegrityError: null value in column "name" violates not-null constraint" error is gone away, as we made it not mandatory field by required=False incremental update.


But I've got next error, same as in question post: "IntegrityError: null value in column "price_unit" violates not-null constraint". This error were originated from "price_unit" field set as mandatory but not displayed in a form view. here we can apply two solutions, either add back to the view all mandatory fields, or make them not mandatory same as for the "name" field above. Then I've got more errors of same kind: "IntegrityError: null value in column "uom_id" violates not-null constraint", followed by: "IntegrityError: null value in column "product_id" violates not-null constraint"...  Just as a quick fix I've added this fields back to the Form View and finally I was able to save the contract without errors. Here is an xml with mandatory fields in place:


<record id="view_contract_form_inherit_be_trans" model="ir.ui.view">
<field name="name">account.analytic.account.inherit</field>
<field name="model">account.analytic.account</field>
<field name="inherit_id" ref="account_analytic_analysis.account_analytic_account_form_form"/>
<field name="arch" type="xml">
<!-- Make the date fields required -->
<xpath expr="//field[@name='date_start']" position="replace">
<field name="date_start" required="True"/>
</xpath>
<xpath expr="//field[@name='date']" position="replace">
<field name="date" required="True"/>
</xpath>
<xpath expr="//field[@name='recurring_invoice_line_ids']" position="after">
<label for="recurring_invoice_car_line_ids" attrs="{'invisible': [('recurring_invoices','=',False)]}"/>
<div attrs="{'invisible': [('recurring_invoices','=',False)]}">
<field name="recurring_invoice_car_line_ids">
<tree string="Account Analytic Lines" editable="bottom">
<field name="car_id" on_change="car_id_change(car_id, car_license_plate, car_mavirent_nummer, car_chassis, car_rent_price)" attrs="{'required':[('car_id', '!=', '')]}"/>
<!--These fields are only required when there is a value in the many2one field product_id' -->
<field name="car_mavirent_nummer" attrs="{'required':[('car_id', '!=', '')]}"/>
<field name="car_license_plate" attrs="{'required':[('car_id', '!=', '')]}"/>
<field name="car_chassis" attrs="{'required':[('car_id', '!=', '')]}"/>
<field name="car_rent_price" attrs="{'required':[('car_id', '!=', '')]}"/>
<field name="car_number_of_units" attrs="{'required':[('car_id', '!=', '')]}"/>
<field name="car_line_tax_id" widget="many2many_tags"/>
<field name="uom_id" />
<field name="product_id" />
<field name="price_unit" />

<field name="car_account_id"/>
</tree>
</field>
</div>
</xpath>
</field>
</record>


Now it's possible to go to sales > contracts, create a new contract and add one car and no products, then click on save and no errors, you can save it successfully. However the above changes are a quick fix, I've not investigated application logic deeper, please adapt solution to your case. For each mandatory field, either add them in the view or make them optional (NOT required) fields as I made optional the "name" field above, and/or review dependency list of your module again if it may change a behavior of your module, as other modules may change fields by incremental updates as well.






4 Comments
Oocademy, Yenthe Van Ginneken Belgium
1/13/16, 7:59 AM

Thanks Temur but I was just missing the 'account' import, I only had 'account_analytic_analysis' and not 'account' and this was giving the strange error. I've updated my question since I now have another strange one.

Oocademy, Yenthe Van Ginneken Belgium
1/14/16, 1:59 AM

@Temur: I've decided to put it on Github so you can see all the code and test it if you'd like / need to. See https://github.com/Yenthe666/Dev/tree/master/aa_maatwerk_be_trans

Oocademy, Yenthe Van Ginneken Belgium
1/22/16, 9:46 AM

@Temur perfect! That was exactly what I was looking for. I'll need some minor changes to have everything perfect but my problem is fixed now. Thanks a lot! Accepted & upvoted! :)

Temur Georgia
1/25/16, 2:03 AM

You're welcome

1
Avatar

Axel Mendoza Cuba

--Axel Mendoza--
13936
| 8 8 10
Camaguey, Cuba
--Axel Mendoza--

DevOps - Full stack - Software Architect - Developer - Technology Integrator

I could help you to develop anything and solve complex problems based on technologies, integrations and tricky stuffs mostly in Python with OpenERP/Odoo, Zato, Django and many others frameworks programming languages and technologies.

I offers consulting services to anyone with an unanswered questions or needs for customizations. Think about it, maybe it's better to have an expert to solve your issues and projects than having a full-time employee trying to understand what to do and how

Reach me at aekroft@gmail.com

Axel Mendoza Cuba
1/27/16, 5:22 PM

@Yenthe, i'm with Pawan on his answer, I don't think that converting the required field into non-required is a good idea, maybe doing that you end up getting broken another scenario.

For me better you follow what it's done on the model account.analytic.account on the method on_change_template building the values for the field recurring_invoice_line_ids, specifically this:

...

invoice_line_ids = []

for x in template.recurring_invoice_line_ids:

invoice_line_ids.append((0, 0, {

'product_id': x.product_id.id,

'uom_id': x.uom_id.id,

'name': x.name,

'quantity': x.quantity,

'price_unit': x.price_unit,

'analytic_account_id': x.analytic_account_id and x.analytic_account_id.id or False,

}))

res['value']['recurring_invoices'] = template.recurring_invoices

res['value']['recurring_interval'] = template.recurring_interval

res['value']['recurring_rule_type'] = template.recurring_rule_type

res['value']['recurring_invoice_line_ids'] = invoice_line_ids

...

Using this solution in your own onchange you need to add the needed fields that @Temur found that need to have a value in your editable tree, at least with invisible="1" so the onchange values could fill those fields and they will be sent to the model create/write and you will don't end up with errors for not-null fields
 

0
Avatar

Pawan India

--Pawan--

1617
| 4 4 8
Hyderabad, India
--Pawan--


Pawan India
1/13/16, 5:14 AM

Yenthe,

There is  a predefined fields called 'name' in account_analytic_invoice_line object which is mandatory by default, which you are not defining while returning it from on change of car field.

So adding {'name': "SOME DATA"} to the returning dictionary from the function.

Regards,

 




6 Comments
Oocademy, Yenthe Van Ginneken Belgium
1/13/16, 5:20 AM

Thanks for the reply Pawan! I was thinking that to initially so at some point I added a name field in the dict but even then I get this error. An example: result.update({'car_name': car_name,'car_license_plate': car_license_plate, 'car_mavirent_nummer': car_mavirent_nummer, 'car_chassis': car_chassis, 'car_rent_price': car_rent_price, 'car_number_of_units': car_number_of_units, 'car_line_tax_id': [(6, 0, goede_btw_id)], 'name': 'Demo name'})

Temur Georgia
1/13/16, 7:17 AM

What about 'name' field in 'account.tax' object (in the goede_btw_id one) ? it's defined as mandatory as well

Oocademy, Yenthe Van Ginneken Belgium
1/13/16, 7:58 AM

@Pawan and @Temur problem seem to came from the fact that I didn't inherit 'account', I had inherited 'account_analytic_analysis' but missed 'account'. I've updated my question since I now have a new issue about [object with reference: price_unit - price.unit]

Pawan India
1/13/16, 9:35 AM

Yenthe,
price_unit also exist in "account_analytic_invoice_line", try adding {'price_unit':0.0} too in your code, and you are returning dictionary at 2 places, please confirm with both the scenarios because i can't find any other scenario for this error

Oocademy, Yenthe Van Ginneken Belgium
1/13/16, 11:52 AM

Pawan, That was exactly my idea too but that doesn't work either. I'll keep getting the error regarding price_unit..

Oocademy, Yenthe Van Ginneken Belgium
1/14/16, 1:59 AM

@Pawan and @Temur: I've decided to put it on Github so you can see all the code and test it if you'd like / need to. See https://github.com/Yenthe666/Dev/tree/master/aa_maatwerk_be_trans

Ask a Question
Keep Informed
0 follower(s)
About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register
Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now