Odoo is the world's easiest all-in-one management software. It includes hundreds of business apps:
CRM | e-Commerce | Accounting | Inventory | PoS | Project management | MRP | etc.
I want to add a module that will change tax computation (def _compute_all in class account.tax) if special check box (field.Boolean) in form view is checked. I use check box since I think it gives clearer information to the user is it active or not.
I just can't get it to work. Fields (float and boolean checkbox) were added and usable but odoo just ignores my changes in tax computation (I test it in POS by adding few products with my custom tax with custom computation).
What is the proper way to do this (way that will not break stuff in the future) and that will work with other modules (basically use same data fields as original odoo-made account module)?
1. Am I even looking at the right method (def_compute_all), class(account.tax) and module (account)?
2. Where is the actual class and method that gives final result to other modules (like POS, Sales, rest of Accounting) and fields?
3. Is that code with @api.v8 and @api.v7 just legacy, or do I have to dynamically change it too?
4. Is there any documentation on developing accounting or tax modules? I am completely lost .
original compute_all method in class AccountTax in module accounting (that might be totally wrong method to change dynamically, or even wrong class?)
def _compute_amount(self, base_amount, price_unit, quantity=1.0, product=None, partner=None): self.ensure_one() if self.amount_type == 'fixed': return math.copysign(self.amount, base_amount) * quantity if (self.amount_type == 'percent' and not self.price_include) or (self.amount_type == 'division' and self.price_include): return base_amount * self.amount / 100 if self.amount_type == 'percent' and self.price_include: return base_amount - (base_amount / (1 + self.amount / 100)) if self.amount_type == 'division' and not self.price_include: return base_amount / (1 - self.amount / 100) - base_amount
class MyTaxCompute(models.Model): _inherit = 'account.tax' custom_tax = fields.Boolean(string='Custom tax computation') custom_tax_field1 = fields.Float(string='Tax 1') custom_tax_field2 = fields.Float(string='Tax 2')
def _compute_amount(self, base_amount, price_unit, quantity=1.0, product=None, partner=None):
#my code here
#res = ...
res = super(MyTaxCompute, self)._compute_amount(base_amount, price_unit, quantity, product, partner)
<record id="view_tax_form_inherited" model="ir.ui.view"> <field name="name">account.tax.form.inherited</field> <field name="model">account.tax</field> <field name="inherit_id" ref="account.view_tax_form"/> <field name="arch" type="xml"> <xpath expr="//page/group" position="after"> <!-- my custom boolean selection field --> <field name="custom_tax" string="Custom tax computation"/> <!-- my custom float fields to put tax rates in --> <field name="custom_tax_field1" string="Tax 1"/> <field name="custom_tax_field2" string="Tax 2"/> </xpath> </field> </record>
Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!
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
|Asked: 2/16/16, 5:22 AM|
|Seen: 584 times|
|Last updated: 2/16/16, 5:29 AM|