How to create stock move in Odoo from custom module? - python

I'm creating a custom module for Odoo.
I have Fabrication Orders with different phases : Order , Preparation , Fabrication , Shipping and Final.
And I have the product_id for the product that I want to Fabricate.
When the "Final" phase comes , the stock for that product need to be increased with the quantity that I choose from a field called "quantity".
Here's the code :
class fabrication_orders(models.Model):
_name = 'proyecto.fabrication_orders'
order_id = fields.Many2one('proyecto.products',required="true",string="Product Id")
name = fields.Char(related='order_id.name',required="true",string="Product Name")
order_number = fields.Char(compute='_get_order_number',string="Order Nº",store="true")
image = fields.Binary(related='order_id.image_medium',string="Image")
quantity = fields.Float(required="true")
date = fields.Datetime(required="true",string="Order Date") ### Order Date
end_date = fields.Datetime(compute='_get_end_date',string="Finish Date",store="true") ### Finish Date
initial_cost = fields.Float(related='order_id.standard_price',string="Initial Cost")
final_cost = fields.Float(compute='_get_order_cost',string="Fabrication Cost")
#venue = fields.Many2one('proyecto.venues',required="true",string="Ship to")
order_state = fields.Selection([
('orden', "Order"),
('preparacion', "Preparation"),
('fabricacion', "Fabrication"),
('envio', "Shipping"),
('final', "Final"),
], default='orden')
#Este metodo pone la fecha final segun la cantidad
#api.depends('date')
def _get_end_date(self):
for d in self:
if d.date:
d.end_date = datetime.now() + timedelta(hours=d.quantity)
#api.depends('order_id')
def _get_order_number(self):
for r in self:
if r.order_id:
r.order_number=str(random.randint(1, 1e6))
#api.multi
def change_order_state(self):
for r in self:
if r.order_state == 'orden':
r.write({'order_state':'preparacion'})
elif r.order_state == 'preparacion':
r.write({'order_state':'fabricacion'})
elif r.order_state == 'fabricacion':
r.write({'order_state':'envio'})
elif r.order_state == 'envio':
r.write({'order_state':'final'})
r.end_date = datetime.now()
elif r.order_state == 'final':
raise ValidationError("La fabricación ha finalizado !")
Can you , please , help to increase the stock quantity of the product ?
Thanks a lot.

I am using Odoo 11. In my use case I wanted to reduce the amount of a product when the stage of my custom model is set to 'done'. Inventory amount is changed by stock.move and stock.move.line. So what I did is creating a stock.move and linked a stock.move.line to it when the state changes to 'done'.
Examples of stock.move creation can be found in addons/stock/tests/test_move.py
Here is a recipe:
(1.) If you do not have one yet, create a location
<record id="location_mylocation" model="stock.location">
<field name="name">MyLocation</field>
<field name="location_id" ref="stock.stock_location_locations_virtual"/>
<field name="usage">inventory</field>
<field name="company_id"></field>
</record>
The usage is set to 'inventory' to reduce the amount of the product. Scrap Orders use the same mechanism.
(2.) Create a stock.move
stock_location = self.env.ref('stock.stock_location_stock')
move = self.env['stock.move'].create({
'name': 'Use on MyLocation',
'location_id': stock_location.id,
'location_dest_id': mylocation.id,
'product_id': product.id,
'product_uom': product.uom_id.id,
'product_uom_qty': qty,
})
move._action_confirm()
move._action_assign()
# This creates a stock.move.line record.
# You could also do it manually using self.env['stock.move.line'].create({...})
move.move_line_ids.write({'qty_done': qty})
move._action_done()

Related

Trying to create a streamlit app that uses user-provided URLs to scrape and return a downloadable df

I'm trying to use this create_df() function in Streamlit to gather a list of user-provided URLs called "recipes" and loop through each URL to return a df I've labeled "res" towards the end of the function. I've tried several approaches with the Streamlit syntax but I just cannot get this to work as I'm getting this error message:
recipe_scrapers._exceptions.WebsiteNotImplementedError: recipe-scrapers exception: Website (h) not supported.
Have a look at my entire repo here. The main.py script works just fine once you've installed all requirements locally, but when I try running the same script with Streamlit syntax in the streamlit.py script I get the above error. Once you run streamlit run streamlit.py in your terminal and have a look at the UI I've create it should be quite clear what I'm aiming at, which is providing the user with a csv of all ingredients in the recipe URLs they provided for a convenient grocery shopping list.
Any help would be greatly appreciated!
def create_df(recipes):
"""
Description:
Creates one df with all recipes and their ingredients
Arguments:
* recipes: list of recipe URLs provided by user
Comments:
Note that ingredients with qualitative amounts e.g., "scheutje melk", "snufje zout" have been ommitted from the ingredient list
"""
df_list = []
for recipe in recipes:
scraper = scrape_me(recipe)
recipe_details = replace_measurement_symbols(scraper.ingredients())
recipe_name = recipe.split("https://www.hellofresh.nl/recipes/", 1)[1]
recipe_name = recipe_name.rsplit('-', 1)[0]
print("Processing data for "+ recipe_name +" recipe.")
for ingredient in recipe_details:
try:
df_temp = pd.DataFrame(columns=['Ingredients', 'Measurement'])
df_temp[str(recipe_name)] = recipe_name
ing_1 = ingredient.split("2 * ", 1)[1]
ing_1 = ing_1.split(" ", 2)
item = ing_1[2]
measurement = ing_1[1]
quantity = float(ing_1[0]) * 2
df_temp.loc[len(df_temp)] = [item, measurement, quantity]
df_list.append(df_temp)
except (ValueError, IndexError) as e:
pass
df = pd.concat(df_list)
print("Renaming duplicate ingredients e.g., Kruimige aardappelen, Voorgekookte halve kriel met schil -> Aardappelen")
ingredient_dict = {
'Aardappelen': ('Dunne frieten', 'Half kruimige aardappelen', 'Voorgekookte halve kriel met schil',
'Kruimige aardappelen', 'Roodschillige aardappelen', 'Opperdoezer Ronde aardappelen'),
'Ui': ('Rode ui'),
'Kipfilet': ('Kipfilet met tuinkruiden en knoflook'),
'Kipworst': ('Gekruide kipworst'),
'Kipgehakt': ('Gemengd gekruid gehakt', 'Kipgehakt met Mexicaanse kruiden', 'Half-om-halfgehakt met Italiaanse kruiden',
'Kipgehakt met tuinkruiden'),
'Kipshoarma': ('Kalkoenshoarma')
}
reverse_label_ing = {x:k for k,v in ingredient_dict.items() for x in v}
df["Ingredients"].replace(reverse_label_ing, inplace=True)
print("Assigning ingredient categories")
category_dict = {
'brood': ('Biologisch wit rozenbroodje', 'Bladerdeeg', 'Briochebroodje', 'Wit platbrood'),
'granen': ('Basmatirijst', 'Bulgur', 'Casarecce', 'Cashewstukjes',
'Gesneden snijbonen', 'Jasmijnrijst', 'Linzen', 'Maïs in blik',
'Parelcouscous', 'Penne', 'Rigatoni', 'Rode kidneybonen',
'Spaghetti', 'Witte tortilla'),
'groenten': ('Aardappelen', 'Aubergine', 'Bosui', 'Broccoli',
'Champignons', 'Citroen', 'Gele wortel', 'Gesneden rodekool',
'Groene paprika', 'Groentemix van paprika, prei, gele wortel en courgette',
'IJsbergsla', 'Kumato tomaat', 'Limoen', 'Little gem',
'Paprika', 'Portobello', 'Prei', 'Pruimtomaat',
'Radicchio en ijsbergsla', 'Rode cherrytomaten', 'Rode paprika', 'Rode peper',
'Rode puntpaprika', 'Rode ui', 'Rucola', 'Rucola en veldsla', 'Rucolamelange',
'Semi-gedroogde tomatenmix', 'Sjalot', 'Sperziebonen', 'Spinazie', 'Tomaat',
'Turkse groene peper', 'Veldsla', 'Vers basilicum', 'Verse bieslook',
'Verse bladpeterselie', 'Verse koriander', 'Verse krulpeterselie', 'Wortel', 'Zoete aardappel'),
'kruiden': ('Aïoli', 'Bloem', 'Bruine suiker', 'Cranberrychutney', 'Extra vierge olijfolie',
'Extra vierge olijfolie met truffelaroma', 'Fles olijfolie', 'Gedroogde laos',
'Gedroogde oregano', 'Gemalen kaneel', 'Gemalen komijnzaad', 'Gemalen korianderzaad',
'Gemalen kurkuma', 'Gerookt paprikapoeder', 'Groene currykruiden', 'Groentebouillon',
'Groentebouillonblokje', 'Honing', 'Italiaanse kruiden', 'Kippenbouillonblokje', 'Knoflookteen',
'Kokosmelk', 'Koreaanse kruidenmix', 'Mayonaise', 'Mexicaanse kruiden', 'Midden-Oosterse kruidenmix',
'Mosterd', 'Nootmuskaat', 'Olijfolie', 'Panko paneermeel', 'Paprikapoeder', 'Passata',
'Pikante uienchutney', 'Runderbouillonblokje', 'Sambal', 'Sesamzaad', 'Siciliaanse kruidenmix',
'Sojasaus', 'Suiker', 'Sumak', 'Surinaamse kruiden', 'Tomatenblokjes', 'Tomatenblokjes met ui',
'Truffeltapenade', 'Ui', 'Verse gember', 'Visbouillon', 'Witte balsamicoazijn', 'Wittewijnazijn',
'Zonnebloemolie', 'Zwarte balsamicoazijn'),
'vlees': ('Gekruide runderburger', 'Half-om-half gehaktballetjes met Spaanse kruiden', 'Kipfilethaasjes', 'Kipfiletstukjes',
'Kipgehaktballetjes met Italiaanse kruiden', 'Kippendijreepjes', 'Kipshoarma', 'Kipworst', 'Spekblokjes',
'Vegetarische döner kebab', 'Vegetarische kaasschnitzel', 'Vegetarische schnitzel'),
'zuivel': ('Ei', 'Geraspte belegen kaas', 'Geraspte cheddar', 'Geraspte grana padano', 'Geraspte oude kaas',
'Geraspte pecorino', 'Karnemelk', 'Kruidenroomkaas', 'Labne', 'Melk', 'Mozzarella',
'Parmigiano reggiano', 'Roomboter', 'Slagroom', 'Volle yoghurt')
}
reverse_label_cat = {x:k for k,v in category_dict.items() for x in v}
df["Category"] = df["Ingredients"].map(reverse_label_cat)
col = "Category"
first_col = df.pop(col)
df.insert(0, col, first_col)
df = df.sort_values(['Category', 'Ingredients'], ascending = [True, True])
print("Merging ingredients by row across all recipe columns using justify()")
gp_cols = ['Ingredients', 'Measurement']
oth_cols = df.columns.difference(gp_cols)
arr = np.vstack(df.groupby(gp_cols, sort=False, dropna=False).apply(lambda gp: justify(gp.to_numpy(), invalid_val=np.NaN, axis=0, side='up')))
# Reconstruct DataFrame
# Remove entirely NaN rows based on the non-grouping columns
res = (pd.DataFrame(arr, columns=df.columns)
.dropna(how='all', subset=oth_cols, axis=0))
res = res.fillna(0)
res['Total'] = res.drop(['Ingredients', 'Measurement'], axis=1).sum(axis=1)
res=res[res['Total'] !=0] #To drop rows that are being duplicated with 0 for some reason; will check later
print("Processing complete!")
return res
Your function create_df needs a list as an argument but st.text_input returs always a string.
In your streamlit.py, replace this df_download = create_df(recs) by this df_download = create_df([recs]). But if you need to handle multiple urls, you should use str.split like this :
def create_df(recipes):
recipes = recipes.split(",") # <--- add this line to make a list from the user-input
### rest of the code ###
if download:
df_download = create_df(recs)
# Output :

Calculating a bill and store the sum to a daily_income

So I'm very new to Python programming and just testing out some stuff in classes and methods.
Im writing a program for a restaurant that have 4 dictionaries that contains key=food and value=price
The dict's are stored in brunch_items, early_bird_items, dinner_items and kids_items, and then I created a object for each of them to my Menu class.
from main import *
dinner_items = {
'crostini with eggplant caponata': 13.00,
'caesar salad': 16.00,
'pizza with quattro formaggi': 11.00,
'duck ragu': 19.50,
'mushroom ravioli (vegan)': 13.50, 'coffee': 2.00, 'espresso': 3.00,
}
kids_items = {
'chicken nuggets': 6.50,
'fusilli with wild mushrooms': 12.00,
'apple juice': 3.00
}
brunch_menu = Menu("Brunch Menu", brunch_items, 1100, 1600)
early_bird_menu = Menu("Early Bird Menu", early_bird_items, 1500, 1800)
dinner_menu = Menu("Dinner Menu", dinner_items, 1700, 1100)
kids_menu = Menu("Kids Menu", kids_items, 1100, 2100)
print(brunch_menu.calculate_bill(["pancakes", "waffles"]))
In the Menu class have the method that returns the different menus and when they are available.
The next method is calculating the bill and return the price for the items.
Output from printing the bill: 16.5
class Menu:
def __init__(self, name, items, start_time, end_time):
self.name = name
self.items = items
self.start_time = start_time
self.end_time = end_time
self.daily_income = 0
def __repr__(self):
return "{} is available from {} - {}".format(self.name, self.start_time, self.end_time)
def calculate_bill(self, purchased_items):
bill = 0
for purchased_item in purchased_items:
if (purchased_item in self.items):
bill += self.items[purchased_item]
return bill
def total_income(self, purchased_items):
return self.daily_income + purchased_items
I dont know where this is going, but the problem is to define a method that takes the calculated bill and store it to a daily income/profit from the purchased items. The idea is to store the total sum from bills
I tried to make self.daily_income = 0 and eventually return that to a variable that keep tracking the payments
Any suggestions to help out?
There are some modeling choices that you have made that I think you will want to revisit, but with light changes to your code you can get a running total by moving daily_income from an instance variable to a shared variable.
class Menu:
daily_income = 0 # shared between all instances
def __init__(self, name, items, start_time, end_time):
self.name = name
self.items = items
self.start_time = start_time
self.end_time = end_time
def __repr__(self):
return "{} is available from {} - {}".format(self.name, self.start_time, self.end_time)
def calculate_bill(self, purchased_items):
bill = 0
for purchased_item in purchased_items:
if (purchased_item in self.items):
bill += self.items[purchased_item]
Menu.daily_income + bill ## Update the shared total
return bill
dinner_items = {
'crostini with eggplant caponata': 13.00,
'caesar salad': 16.00,
'pizza with quattro formaggi': 11.00,
'duck ragu': 19.50,
'mushroom ravioli (vegan)': 13.50, 'coffee': 2.00, 'espresso': 3.00,
}
kids_items = {
'chicken nuggets': 6.50,
'fusilli with wild mushrooms': 12.00,
'apple juice': 3.00
}
## ---------------------------
## Simulate table A
## ---------------------------
my_bill = Menu("Dinner Menu", dinner_items, 1700, 1100).calculate_bill(["caesar salad", "duck ragu"])
my_bill += Menu("Kids Menu", kids_items, 1100, 2100).calculate_bill(["chicken nuggets"])
Menu.daily_income += my_bill
print(f"Total Table Bill: ${my_bill}. Our revenue so far: ${Menu.daily_income}")
## ---------------------------
## ---------------------------
## Simulate table B
## ---------------------------
my_bill = Menu("Dinner Menu", dinner_items, 1700, 1100).calculate_bill(["pizza with quattro formaggi"])
Menu.daily_income += my_bill
print(f"Total Table Bill: ${my_bill}. Our revenue so far: ${Menu.daily_income}")
## ---------------------------
That should give you:
Total Table Bill: $42.0. Our revenue so far: $42.0
Total Table Bill: $11.0. Our revenue so far: $53.0

Python - Create list out of all variables in same .py file

So I have this code below of categories and I will sometimes update it by adding a new category, then I have to manually add that category to the list at the bottom INITIAL_GOAL_CATEGORIES it'd be much easier if this list was automatically updated whenever I create a new dict variable. Is there a way to do this? I export the INITIAL_GOAL_CATEGORIES variable and use it elsewhere so if I can set that variable name to a list of all other variables that'd be great. This file will only contain dicts of categories and the list of all of them at the bottom.
categories.py
# Categories
ART = dict(name='Art', emoji='🎨')
CULINARY = dict(name='Culinary', emoji='🍳')
DIET = dict(name='Diet', emoji='🥗')
DIY = dict(name='DIY', emoji='🔨')
FINANCE = dict(name='Finance', emoji='💰')
FITNESS = dict(name='Fitness', emoji='👟')
GAMING = dict(name='Gaming', emoji='🕹️')
MARTIAL_ARTS = dict(name='Martial Arts', emoji='🥋')
MUSIC = dict(name='Music', emoji='🎵')
RELATIONSHIP = dict(name='Relationship', emoji='💗')
SELF_CARE = dict(name='Self-Care', emoji='🤗')
SELF_IMPROVEMENT = dict(name='Self-Improvement', emoji='✨')
STREAMING = dict(name='Streaming', emoji='⏺️')
TRAVEL = dict(name='Travel', emoji='✈️')
WEIGHT_TRAINING = dict(name='Weight Training', emoji='🏋️')
INITIAL_GOAL_CATEGORIES = [ART, CULINARY, DIET, DIY, FITNESS, GAMING, MARTIAL_ARTS, MUSIC,
RELATIONSHIP, SELF_IMPROVEMENT, SELF_CARE, STREAMING, TRAVEL,
WEIGHT_TRAINING]
If you want to create a list that update itself when you add this kind of global values, here what you need:
# Categories
ART = dict(name='Art', emoji='🎨')
CULINARY = dict(name='Culinary', emoji='🍳')
DIET = dict(name='Diet', emoji='🥗')
DIY = dict(name='DIY', emoji='🔨')
FINANCE = dict(name='Finance', emoji='💰')
FITNESS = dict(name='Fitness', emoji='👟')
GAMING = dict(name='Gaming', emoji='🕹️')
MARTIAL_ARTS = dict(name='Martial Arts', emoji='🥋')
MUSIC = dict(name='Music', emoji='🎵')
RELATIONSHIP = dict(name='Relationship', emoji='💗')
SELF_CARE = dict(name='Self-Care', emoji='🤗')
SELF_IMPROVEMENT = dict(name='Self-Improvement', emoji='✨')
STREAMING = dict(name='Streaming', emoji='⏺️')
TRAVEL = dict(name='Travel', emoji='✈️')
WEIGHT_TRAINING = dict(name='Weight Training', emoji='🏋️')
INITIAL_GOAL_CATEGORIES = [value for name, value in globals().items() if
name.isupper()]
This go through all values in globals() and
check if the name of the value is upper case. If it met the criteria, it is a category and we add it to the categories list.
But as said in comments: a dictionary is better:
# Categories
INITIAL_GOAL_CATEGORIES = {
'Art': {'emoji': '🎨'},
'Culinary': {'emoji': '🍳'},
'Diet': {'emoji': '🥗'},
'DIY': {'emoji': '🔨'},
'Finance': {'emoji': '💰'},
'Fitness': {'emoji': '👟'},
'Gaming': {'emoji': '🕹️'},
'Martial Arts': {'emoji': '🥋'},
'Music': {'emoji': '🎵'},
'Relationship': {'emoji': '💗'},
'Self-Care': {'emoji': '🤗'},
'Self-Improvement': {'emoji': '✨'},
'Streaming': {'emoji': '⏺️'},
'Travel': {'emoji': '✈️'},
'Weight Training': {'emoji': '🏋️'},
}

Odoo 10 - Retrieve the value of a field of another model

Here is code:
Target model:
class SchoolYears(models.Model):
_name = "ecole.partner.school.years"
_rec_name = "school_years" # POUR ASSIGNER PAR DEFAUT UN AUTRE CHAMP AUTRE QUE NAME
_order = 'id desc'
school_years = fields.Char(string='School year', required=True, copy=False)
year_begin_date = fields.Date(string='Start date', required=True, copy=False)
year_end_date = fields.Date(string='End date', required=True, copy=False)
default_school_year = fields.Boolean(string='Current school year', copy=False)
period_school_year = fields.Boolean(string='Registration period', copy=False)
active = fields.Boolean(default=True)
Targeted fields:-> year_begin_date = fields.Date(string='Start date', required=True, copy=False)
Model where I want to access the fields:
class ResPartnerSchool(models.Model):
_name = 'ecole.partner.school'
_order = 'id desc'
#api.multi
def _get_begin_date(self):
domain = [('period_school_year', '=', False), ('default_school_year', '=', True)]
begin_date_id = self.env['ecole.partner.school.years'].search(domain, limit=1).year_begin_date
begin_date = fields.Date.from_string(begin_date_id)
date_j = datetime.date.today()
if begin_date_id:
if begin_date > date_j:
return begin_date_id
else:
return date_j
...
school_year_id = fields.Many2one(string='Period',
ondelete='SET NULL',
comodel_name="ecole.partner.school.years",
default=_get_period_year)
school_registration = fields.Date(string='Beginning',
copy=False,
default=_get_begin_date)
...
Here is the view:
I want to get the correct start date of the school year related to school_years which is of type char and which is a Many2one in the model ecole.partner.school.
I know there are many ways to do this, especially with a "related field". Except that I have a function that allows me to recover the date of the day as of the beginning of the school year when one is in full in a school period.
Currently my function is written in "hard" -> this is what we see in the variable "domain". And I do not want to use "related field" in my school_registration field.
Do you have an idea to get the right start date when choosing a school year?
Thank you
You can try with a computed fields :
school_year_id = fields.Many2one(string='Period',
ondelete='SET NULL',
comodel_name="ecole.partner.school.years",
default=_get_period_year)
school_registration = fields.Date(string='Beginning',
copy=False,
compute=_get_begin_date)
#api.multi
#api.depends('school_year_id')
def _get_begin_date(self):
for record in self:
record.school_registration = record.school_year_id.year_begin_date

Odoo 11 How to override compute_all() method?

I am developping a module to use a custom formula for the amount calculation method in invoices and sales orders.
The line amount formula should be : nbJours * price_unit * quantity instead of the default formula : price_unit * quantity
I added a custom field to AccountInvoiceLine class by inheriting it as following :
class AccountInvoiceLine(models.Model):
_inherit = "account.invoice.line"
# Nombre de jours de location
nombreJours = fields.Integer("Nombre de jours",default=1,required=True)
#api.multi
#api.depends('nombreJours','price_unit', 'discount', 'invoice_line_tax_ids', 'quantity', 'product_id', 'invoice_id.partner_id', 'invoice_id.currency_id', 'invoice_id.company_id', 'invoice_id.date_invoice', 'invoice_id.date')
def _compute_price(self):
...
...
if self.invoice_line_tax_ids:
taxes = self.invoice_line_tax_ids.compute_all(self.nombreJours, price, currency, self.quantity, product=self.product_id, partner=self.invoice_id.partner_id)
# Calcul du sous-total de la ligne
self.price_subtotal = price_subtotal_signed = taxes['total_excluded'] if taxes else self.quantity * price * self.nombreJours
self.price_total = taxes['total_included'] if taxes else self.price_subtotal
...
...
And I also need to set the custom formula in the AccountTax class. I tried to override the compute_all() method :
# Modification du modèle de Taxes
class AccountTax(models.Model):
_inherit = 'account.tax'
#api.multi
def compute_all(self, nbJrs=1, price_unit=1, currency=None, quantity=1.0, product=None, partner=None):
...
...
if not base_values:
odooAmount = price_unit * quantity
customAmount = nbJrs * odooAmount
total_excluded = total_included = base = round( customAmount , prec)
else:
total_excluded, total_included, base = base_values
...
...
return {
'taxes': sorted(taxes, key=lambda k: k['sequence']),
'total_excluded': currency.round(total_excluded) if round_total else total_excluded,
'total_included': currency.round(total_included) if round_total else total_included,
'base': base,
}
I've successfully updated my module, but when I try to add a product in a new invoice I get this error :
... ... ...
File "/OdooERP/Odoo 11.0/addons/account/models/account_invoice.py", line 618, in _onchange_invoice_line_ids taxes_grouped = self.get_taxes_values()
File "/OdooERP/Odoo 11.0/addons/account/models/account_invoice.py", line 889, in get_taxes_values taxes = line.invoice_line_tax_ids.compute_all(price_unit, self.currency_id, line.quantity, line.product_id, self.partner_id)['taxes']
File "/OdooERP/Instances/xaymalab/addons/sunu_location_event/models/accountinvoice.py",line 82, in compute_all odooAmount = price_unit * quantity
TypeError: unsupported operand type(s) for *: 'res.currency' and 'product.product'
When I remove "nbJrs" parameter in the definition, it works!
The values shift one parameter to the right.
Can anybody help me out regarding it?
You've made a mistake on overriding compute_all() of account.tax. Seems you've added a new parameter nbJrs. The original Method:
def compute_all(self, price_unit, currency=None,
quantity=1.0, product=None, partner=None)
and yours:
def compute_all(self, nbJrs=1, price_unit=1, currency=None,
quantity=1.0, product=None, partner=None):
That just won't work this way. The error is: You're multiplying the value of currency with the value of product, because the values shift one parameter to the right.
How I solved this :
I was trying to override the compute_all() by adding a new parameter. It was the wrong way.
I updated the _compute_price() by adding a new variable "rentalprice" and passing it to compute_all():
def _compute_price(self):
currency = self.invoice_id and self.invoice_id.currency_id or None
price = self.price_unit * (1 - (self.discount or 0.0) / 100.0)
# Prix unitaire d'un article pendant la durée totale de location:
rentalprice = self.nombrejours * price
taxes = False
if self.invoice_line_tax_ids:
taxes = self.invoice_line_tax_ids.compute_all(rentalprice, currency, self.quantity, product=self.product_id, partner=self.invoice_id.partner_id)
I removed the AccountTax inheritance code because I no longer need it, updated my module and now it's working.
Thanks to #CZoellner for helping me to better understand what I was missing.

Categories