Skip to content

Commit 31494a1

Browse files
committed
💣 Added relation to the product.template
Signed-off-by: Vildan Safin <safin@it-projects.info>
1 parent 68cec76 commit 31494a1

3 files changed

Lines changed: 37 additions & 1 deletion

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<!-- Copyright 2020 Vildan Safin <https://www.it-projects.info/team/Enigma228322>
2+
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).-->
3+
<odoo>
4+
<record id="product_user" model="product.template">
5+
<field name="name">User</field>
6+
<field name="standart_price">10</field>
7+
</record>
8+
</odoo>

saas_apps/models/saas_apps.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class SAASDependence(models.Model):
6161
default=lambda s: s.env.user.company_id,
6262
)
6363
currency_id = fields.Many2one("res.currency", compute="_compute_currency_id")
64+
product_id = fields.Many2many('product.template')
6465

6566
def _compute_currency_id(self):
6667
self.currency_id = self.company_id.currency_id
@@ -92,11 +93,24 @@ def refresh_lines(self):
9293
'icon_path': base_icon_path
9394
})
9495

96+
def make_product(self, app):
97+
new_product = self.env["product.template"].create({
98+
'name': app.module_name,
99+
'standard_price': app.year_price
100+
})
101+
for product in app.product_id:
102+
product.unlink()
103+
app.product_id = new_product
104+
105+
def change_product_price(self, app, price):
106+
app.product_id.standard_price = price
107+
95108
def compute_price(self):
96109
sum = 0
97110
for module in self.dependencies:
98111
sum += module.year_price
99112
self.year_price = sum
113+
self.change_product_price(self, sum)
100114
sum = 0
101115
for module in self.dependencies:
102116
sum += module.month_price
@@ -140,6 +154,15 @@ def write(self, vals):
140154
# If value of allow_to_sell changed, other sets allow_to_sell vars should be changed too
141155
if "allow_to_sell" in vals and vals['allow_to_sell']:
142156
self.change_allow_to_sell()
157+
if "year_price" in vals:
158+
self.change_product_price(self, vals["year_price"])
159+
return res
160+
161+
@api.model
162+
def create(self, vals):
163+
res = super(SAASDependence, self).create(vals)
164+
if "module_name" in vals:
165+
self.make_product(res)
143166
return res
144167

145168

@@ -163,3 +186,8 @@ def change_base_template(self):
163186
old_base_template = self.search([('set_as_base', '=', True)])
164187
if old_base_template:
165188
old_base_template.write({'set_as_base': False})
189+
190+
class SAASProduct(models.Model):
191+
_inherit = 'product.template'
192+
193+
application = fields.Many2many('saas.line')

saas_apps/static/src/css/calculator.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@
119119
margin-left: 10%;
120120
max-width: 50%;
121121
}
122-
122+
123123
.app{
124124
margin-left: 7px;
125125
max-width: 31%;

0 commit comments

Comments
 (0)