diff --git a/yuthon_property/wizard/meter_price_wizard.py b/yuthon_property/wizard/meter_price_wizard.py index eacefff64..7b29b2afc 100644 --- a/yuthon_property/wizard/meter_price_wizard.py +++ b/yuthon_property/wizard/meter_price_wizard.py @@ -17,6 +17,26 @@ class MeterPriceWizard(models.TransientModel): default=lambda self: str(datetime.now().year)) price = fields.Float(string='计费单价', digits=(16, 4)) + @api.onchange("select_time", "select_year") + def _get_price(self): + year = int(self.select_year) + month = int(self.select_time) + start_date = datetime(year, month, 1).date() + if month == 12: + next_month = 1 + next_year = year + 1 + else: + next_month = month + 1 + next_year = year + end_date = (datetime(next_year, next_month, 1).date() - timedelta(days=1)) + logs_id = self.env['hydropower.logs'].search([('logs_date', '>=', start_date), ('logs_date', '<=', end_date), + ('meter_type', '=', 'electric') + ], limit=1) + if logs_id: + self.price = logs_id.price + else: + self.price = 0.0 + def confirm(self): year = int(self.select_year) month = int(self.select_time) diff --git a/yuthon_property/wizard/water_price_wizard.py b/yuthon_property/wizard/water_price_wizard.py index 47e7bbf8b..77f321d86 100644 --- a/yuthon_property/wizard/water_price_wizard.py +++ b/yuthon_property/wizard/water_price_wizard.py @@ -17,6 +17,27 @@ class WaterPriceWizard(models.TransientModel): default=lambda self: str(datetime.now().year)) price = fields.Float(string='计费单价', digits=(16, 4)) + @api.onchange("select_time", "select_year") + def _get_price(self): + year = int(self.select_year) + month = int(self.select_time) + start_date = datetime(year, month, 1).date() + if month == 12: + next_month = 1 + next_year = year + 1 + else: + next_month = month + 1 + next_year = year + end_date = (datetime(next_year, next_month, 1).date() - timedelta(days=1)) + logs_id = self.env['hydropower.logs'].search([('logs_date', '>=', start_date), ('logs_date', '<=', end_date), + ('meter_type', '=', 'water') + ], + limit=1) + if logs_id: + self.price = logs_id.price + else: + self.price = 0.0 + def confirm(self): year = int(self.select_year) month = int(self.select_time)