Commit 4fd5831c by François C.

Maj module lacagette_sales_helper

parent c9fc08cf
......@@ -6,8 +6,9 @@
Retrieve and display products information to help with future sales - via API or Odoo Menu""",
'description': """
Display on the product page buttons with Total Losses, Autoconsommation, Employees meals...
Odoo system parameters need to be set: losses, autoconso and meals locations id
Display on the product page buttons with total losses, autoconsommation,
employees meals & and nb of discounts in sales.\n
These Odoo system parameters need to be set: losses, autoconso and meals locations id.
""",
'author': "damien.moulard",
......
......@@ -29,6 +29,7 @@ class ProductTemplate(models.Model):
total_losses_qty = fields.Float(string="Total Pertes", compute='_compute_total_losses_qty')
total_autoconso_qty = fields.Float(string="Total Autoconsommation", compute='_compute_total_autoconso_qty')
total_meals_qty = fields.Float(string="Total Repas Salariés", compute='_compute_total_meals_qty')
total_discounts_qty = fields.Float(string="Total Remises", compute='_compute_total_discounts_qty')
sql_stock_move = """
SELECT sum(product_uom_qty) as qty
......@@ -41,7 +42,7 @@ class ProductTemplate(models.Model):
@api.multi
def _compute_total_losses_qty(self):
for product_t in self:
qty = -1
qty = 0
try:
conf = self.env['ir.config_parameter']
losses_loc_id = conf.get_param("lacagette_sales_helper.losses_location_id")
......@@ -57,7 +58,7 @@ class ProductTemplate(models.Model):
@api.multi
def _compute_total_autoconso_qty(self):
for product_t in self:
qty = -1
qty = 0
try:
conf = self.env['ir.config_parameter']
autoconso_loc_id = conf.get_param("lacagette_sales_helper.autoconso_location_id")
......@@ -73,7 +74,7 @@ class ProductTemplate(models.Model):
@api.multi
def _compute_total_meals_qty(self):
for product_t in self:
qty = -1
qty = 0
try:
conf = self.env['ir.config_parameter']
meals_loc_id = conf.get_param("lacagette_sales_helper.meals_location_id")
......@@ -87,6 +88,29 @@ class ProductTemplate(models.Model):
product_t.total_meals_qty = qty
@api.multi
def _compute_total_discounts_qty(self):
for product_t in self:
qty = 0
try:
sql = """
SELECT qty
FROM pos_order_line
WHERE product_id = (SELECT id FROM product_product WHERE product_tmpl_id = %s)
AND discount > 0
"""
self.env.cr.execute(sql , [product_t.id])
req_res = self.env.cr.dictfetchall()
if len(req_res) > 0:
for i in req_res:
qty += req_res[0]['qty']
qty = round(qty, 3)
except Exception as e:
print(str(e))
product_t.total_discounts_qty = qty
@api.multi
def view_losses_client_action(self):
return {
'res_model': 'lacagette.sales_helper',
......@@ -112,3 +136,7 @@ class ProductTemplate(models.Model):
'tag': 'custom_product_meals',
'target': 'new',
}
@api.multi
def view_discounts_client_action(self):
return 0;
......@@ -42,4 +42,18 @@
</div>
</field>
</record>
<record id="view_template_discount_history_form" model="ir.ui.view">
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_form_view"/>
<field name="arch" type="xml">
<div name="button_box" position="inside">
<button name="view_discounts_client_action" type="object"
icon="fa-dollar" class="oe_stat_button display_discounts_stats"
groups="stock.group_stock_manager"
string="">
<field name="total_discounts_qty" widget="statinfo"/>
</button>
</div>
</field>
</record>
</odoo>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment