Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion addons/product_matrix/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from . import models
11 changes: 3 additions & 8 deletions addons/product_matrix/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,15 @@
'category': 'Sales/Sales',
'depends': ['account'],
# Account dependency for section_and_note widget.
'data': [
'data/res_groups.xml',
'views/matrix_templates.xml',
],
'demo': [
'data/product_matrix_demo.xml',
],
'data': ['data/res_groups.xml', 'views/matrix_templates.xml'],
'demo': ['data/product_matrix_demo.xml'],
'assets': {
'web.assets_backend': [
'product_matrix/static/src/js/matrix_configurator_hook.js',
'product_matrix/static/src/js/product_matrix_dialog.js',
'product_matrix/static/src/scss/product_matrix.scss',
'product_matrix/static/src/xml/**/*',
],
]
},
'author': 'Odoo S.A.',
'license': 'LGPL-3',
Expand Down
30 changes: 16 additions & 14 deletions addons/product_matrix/models/product_template.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,34 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import itertools

from odoo import models, fields
from odoo import fields, models


class ProductTemplate(models.Model):
_inherit = 'product.template'

def _get_template_matrix(self, **kwargs):
self.ensure_one()
company_id = kwargs.get('company_id', None) or self.company_id or self.env.company
currency_id = kwargs.get('currency_id', None) or self.currency_id
company_id = kwargs.get('company_id') or self.company_id or self.env.company
currency_id = kwargs.get('currency_id') or self.currency_id
display_extra = kwargs.get('display_extra_price', False)
attribute_lines = self.valid_product_template_attribute_line_ids

Attrib = self.env['product.template.attribute.value']
first_line_attributes = attribute_lines[0].product_template_value_ids._only_active()
attribute_ids_by_line = [line.product_template_value_ids._only_active().ids for line in attribute_lines]
attribute_ids_by_line = [
line.product_template_value_ids._only_active().ids for line in attribute_lines
]

header = [{"name": self.display_name}] + [
attr._grid_header_cell(
fro_currency=self.currency_id,
to_currency=currency_id,
company=company_id,
display_extra=display_extra
) for attr in first_line_attributes]
display_extra=display_extra,
)
for attr in first_line_attributes
]

result = [[]]
for pool in attribute_ids_by_line:
Expand All @@ -40,7 +43,8 @@ def _get_template_matrix(self, **kwargs):
fro_currency=self.currency_id,
to_currency=currency_id,
company=company_id,
display_extra=display_extra)
display_extra=display_extra,
)
result = [row_header_cell]

for cell in row:
Expand All @@ -50,14 +54,11 @@ def _get_template_matrix(self, **kwargs):
result.append({
"ptav_ids": cell,
"qty": 0,
"is_possible_combination": is_possible_combination
"is_possible_combination": is_possible_combination,
})
matrix.append(result)

return {
"header": header,
"matrix": matrix,
}
return {"header": header, "matrix": matrix}


class ProductTemplateAttributeValue(models.Model):
Expand All @@ -81,5 +82,6 @@ def _grid_header_cell(self, fro_currency, to_currency, company, display_extra=Tr
if extra_price:
header_cell['currency_id'] = to_currency.id
header_cell['price'] = fro_currency._convert(
extra_price, to_currency, company, fields.Date.today())
extra_price, to_currency, company, fields.Date.today()
)
return header_cell
1 change: 0 additions & 1 deletion addons/product_matrix/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from . import common
63 changes: 31 additions & 32 deletions addons/product_matrix/tests/common.py
Original file line number Diff line number Diff line change
@@ -1,49 +1,48 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo.tests import tagged, common

from odoo.tests import common

class TestMatrixCommon(common.HttpCase):

class TestMatrixCommon(common.HttpCase):
def setUp(self):
super(TestMatrixCommon, self).setUp()
super().setUp()

# Prepare relevant test data
# This is not included in demo data to avoid useless noise
product_attributes = self.env['product.attribute'].create([{
'name': 'PA1',
'create_variant': 'always',
'sequence': 1
}, {
'name': 'PA2',
'create_variant': 'always',
'sequence': 2
}, {
'name': 'PA3',
'create_variant': 'dynamic',
'sequence': 3
}, {
'name': 'PA4',
'create_variant': 'no_variant',
'sequence': 4
}])

self.env['product.attribute.value'].create([{
'name': 'PAV' + str(product_attribute.sequence) + str(i),
'attribute_id': product_attribute.id
} for i in range(1, 3) for product_attribute in product_attributes])
product_attributes = self.env['product.attribute'].create([
{'name': 'PA1', 'create_variant': 'always', 'sequence': 1},
{'name': 'PA2', 'create_variant': 'always', 'sequence': 2},
{'name': 'PA3', 'create_variant': 'dynamic', 'sequence': 3},
{'name': 'PA4', 'create_variant': 'no_variant', 'sequence': 4},
])

self.env['product.attribute.value'].create([
{
'name': 'PAV' + str(product_attribute.sequence) + str(i),
'attribute_id': product_attribute.id,
}
for i in range(1, 3)
for product_attribute in product_attributes
])

self.matrix_template = self.env['product.template'].create({
'name': "Matrix",
'type': "consu",
'uom_id': self.ref("uom.product_uom_unit"),
'attribute_line_ids': [(0, 0, {
'attribute_id': attribute.id,
'value_ids': [(6, 0, attribute.value_ids.ids)]
}) for attribute in product_attributes],
'attribute_line_ids': [
(
0,
0,
{'attribute_id': attribute.id, 'value_ids': [(6, 0, attribute.value_ids.ids)]},
)
for attribute in product_attributes
],
})

def get_ptav(pav_name):
return self.env['product.template.attribute.value']\
.search([('product_attribute_value_id.name', '=', pav_name)])
return self.env['product.template.attribute.value'].search([
('product_attribute_value_id.name', '=', pav_name)
])

get_ptav('PAV12').price_extra = 50
get_ptav('PAV31').price_extra = -25
15 changes: 6 additions & 9 deletions addons/sale/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo.tools.misc import str2bool
from odoo.tools.sql import SQL

from . import const
from . import controllers
from . import models
from . import report
from . import wizard
from . import const, controllers, models, report, wizard


def _pre_init_sale(env):
Expand All @@ -17,11 +12,13 @@ def _pre_init_sale(env):
The different fields are all NULL (falsy) for existing AAL,
the computation is way more efficient in SQL than in Python.
"""
env.cr.execute(SQL("""
env.cr.execute(
SQL("""
ALTER TABLE account_analytic_line
ADD COLUMN IF NOT EXISTS order_id INT4,
ADD COLUMN IF NOT EXISTS so_line INT4
"""))
""")
)


def _post_init_hook(env):
Expand All @@ -37,5 +34,5 @@ def _synchronize_crons(env):

def _setup_downpayment_account(env):
env['account.chart.template']._load_pre_defined_data({
'res.company': {'downpayment_account_id'},
'res.company': {'downpayment_account_id'}
})
17 changes: 3 additions & 14 deletions addons/sale/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,26 @@
'security/ir.model.access.csv',
'security/res_groups.xml',
'security/ir_rules.xml',

'report/account_invoice_report_views.xml',
'report/ir_actions_report_templates.xml',
'report/ir_actions_report.xml',
'report/sale_report_views.xml',

'data/analytic_plan_data.xml',
'data/ir_cron.xml',
'data/ir_sequence_data.xml',
'data/mail_message_subtype_data.xml',
'data/mail_template_data.xml',
'data/portal_entry_data.xml',
'data/sale_tour.xml',
'data/ir_config_parameter.xml', # Needs mail_template_data

'data/ir_config_parameter.xml', # Needs mail_template_data
'wizard/account_accrued_orders_wizard_views.xml',
'wizard/mass_cancel_orders_views.xml',
'wizard/payment_link_wizard_views.xml',
'wizard/res_config_settings_views.xml',
'wizard/sale_make_invoice_advance_views.xml',
'wizard/sale_order_discount_views.xml',

# Define sale order views before their references
'views/sale_order_views.xml',

'views/account_views.xml',
'views/account_analytic_line_views.xml',
'views/crm_team_views.xml',
Expand All @@ -56,13 +51,9 @@
'views/sale_order_line_views.xml',
'views/sale_portal_templates.xml',
'views/utm_campaign_views.xml',

'views/sale_menus.xml', # Last because referencing actions defined in previous files
],
'demo': [
'data/product_demo.xml',
'data/sale_demo.xml',
],
'demo': ['data/product_demo.xml', 'data/sale_demo.xml'],
'assets': {
'web.assets_backend': [
'sale/static/src/scss/sale_onboarding.scss',
Expand Down Expand Up @@ -102,9 +93,7 @@
'sale/static/tests/sale_test_helpers.js',
'sale/static/tests/**/*.test.js',
],
'web.report_assets_common': [
'sale/static/src/scss/sale_report.scss',
],
'web.report_assets_common': ['sale/static/src/scss/sale_report.scss'],
},
'pre_init_hook': '_pre_init_sale',
'post_init_hook': '_post_init_hook',
Expand Down
4 changes: 1 addition & 3 deletions addons/sale/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from . import combo_configurator
from . import portal
from . import product_configurator
from . import combo_configurator, portal, product_configurator
Loading