@@ -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' )
0 commit comments