Skip to content

Commit

Permalink
[IMP] contract_sale_school: take into account wizards dates (#1085)
Browse files Browse the repository at this point in the history
  • Loading branch information
oihane committed Apr 29, 2021
1 parent f7dd199 commit 2831544
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 26 deletions.
2 changes: 1 addition & 1 deletion contract_sale_school/data/contract_sale_school_data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
<field name="name">Discontinued</field>
<field name="terminate_comment_required">False</field>
</record>
</odoo>
</odoo>
26 changes: 15 additions & 11 deletions contract_sale_school/models/contract_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,18 @@ def create_contract_line(
"uom_id": product.uom_id.id,
"discount": discount,
}
date_start = date_start or academic_year.date_start
date_end = date_end or academic_year.date_end
if product.recurrent_punctual == "recurrent":
if not contract.check_line_exists(product):
if date_start.month != product.month_start.number:
date_start = date_start.replace(
month=product.month_start.number, day=1)
if date_end != product.end_month.number:
date_end = date_end.replace(
month=product.end_month, day=1)
if not date_start:
date_start = academic_year.date_start
if date_start.month != product.month_start.number:
date_start = date_start.replace(
month=product.month_start.number, day=1)
if not date_end:
date_end = academic_year.date_end
if date_end != product.end_month.number:
date_end = date_end.replace(
month=product.end_month, day=1)
line_vals.update({
"name": product.name,
"date_start": date_start,
Expand All @@ -45,6 +47,8 @@ def create_contract_line(
})
line_obj.create(line_vals)
elif product.recurrent_punctual == "punctual":
date_start = date_start or academic_year.date_start
date_end = date_end or academic_year.date_end
for month in product.punctual_month_ids:
date_end = date_end.replace(day=1)
if date_start.month <= month.number:
Expand All @@ -62,9 +66,9 @@ def create_contract_line(
else:
line_vals.update({
"name": product.name,
"date_start": date_start,
"date_end": date_end,
"recurring_next_date": date_end,
"date_start": date_start or academic_year.date_start,
"date_end": date_end or academic_year.date_end,
"recurring_next_date": date_end or academic_year.date_end,
})
line_obj.create(line_vals)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
<record model="res.groups" id="contract.can_terminate_contract">
<field name="users" eval="[(4, ref('base.user_root'))]" />
</record>
</odoo>
</odoo>
5 changes: 3 additions & 2 deletions stock_picking_default_package/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
{
'name': "Default Package for Product Category",
'summary': """
Add default package type depending on the product category.
Add default package type depending on the product category.
""",
"author": "AvanzOSC",
'website': 'http://www.avanzosc.es/',
'version': '1.0',
'version': '12.0.1.0.0',
"license": "AGPL-3",
'depends': ['product', 'stock', 'stock_picking_sorted'],
'data': [
'views/product_category_view.xml',
Expand Down
1 change: 0 additions & 1 deletion stock_picking_default_package/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@

from . import product_category
from . import stock
6 changes: 3 additions & 3 deletions stock_picking_default_package/models/product_category.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Copyright 2021 Leire Martinez de Santos - AvanzOSC
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
from odoo import _, api, fields, models
from odoo import fields, models


class ProductCategory(models.Model):
_inherit = "product.category"

default_packaging_id = fields.Many2one('product.packaging', string='Default Packaging')

default_packaging_id = fields.Many2one(
comodel_name='product.packaging', string='Default Packaging')
19 changes: 12 additions & 7 deletions stock_picking_default_package/models/stock.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,37 @@
# Copyright 2021 Leire Martinez de Santos - AvanzOSC
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
from odoo import api, fields, models
from odoo import fields, models


class StockMoveLine(models.Model):
_inherit = "stock.move.line"

default_packaging_id = fields.Many2one('product.packaging', string='Default Packaging',
related='product_id.categ_id.default_packaging_id')
default_packaging_id = fields.Many2one(
comodel_name='product.packaging', string='Default Packaging',
related='product_id.categ_id.default_packaging_id')


class StockQuantPackage(models.Model):
_inherit = 'stock.quant.package'

expected_quantity = fields.Integer(string='Expected quantity', compute='_compute_expected_qty')
quantity_in_package = fields.Integer(string='Quantity in package', compute='_compute_qty_in_package')
expected_quantity = fields.Integer(
string='Expected quantity', compute='_compute_expected_qty')
quantity_in_package = fields.Integer(
string='Quantity in package', compute='_compute_qty_in_package')

def _compute_qty_in_package(self):
for res in self:
stock_move_line_ids = self.env['stock.move.line'].search([('result_package_id.id', '=', res.id)])
stock_move_line_ids = self.env['stock.move.line'].search([
('result_package_id.id', '=', res.id)])
total_lines_qty = 0
for line in stock_move_line_ids:
total_lines_qty += line.qty_done
res.quantity_in_package = total_lines_qty

def _compute_expected_qty(self):
for res in self:
stock_move_line_ids = self.env['stock.move.line'].search([('result_package_id.id', '=', res.id)])
stock_move_line_ids = self.env['stock.move.line'].search([(
'result_package_id.id', '=', res.id)])
total_lines_qty = 0
for line in stock_move_line_ids:
total_lines_qty += line.product_uom_qty
Expand Down

0 comments on commit 2831544

Please sign in to comment.