Thursday, October 3, 2019

period between start date and end date in odoo



We can calculate the period of time between start date and end date by following the steps bellow

  • go to the python class and define start_date field which will contain the start date , end_date field which will contain the end date , period_years which will contain the years between the start date and the end date which we will calculate , period_months which will contain the months between the start date and the end date which we will calculate , period_days which will contain the days between the start date and the end date which we will calculate as bellow

start_date = fields.Date(string="Start Date", required=True)
end_date = fields.Date(string="End Date", required=True)
period_years = fields.Integer(string="Years", compute="get_period_time")
period_months = fields.Integer(string="Months", compute="get_period_time")
period_days = fields.Integer(string="Days", compute="get_period_time")

  • create get_period_time function which will calculate the date between the start date and the end date as

    @api.one
    def get_period_time(self):
        """
        function to calcolate the period of time 
        when we know the start date and the end date
        """
        if self.start_date and self.end_date:
            start_date = str(self.start_date)
            end_date = str(self.end_date)

            start_year_as_int = int(start_date[0]+start_date[1]+start_date[2]+start_date[3])
            start_month_as_int = int(start_date[5]+start_date[6])
            start_day_as_int = int(start_date[8]+start_date[9])

            end_year_as_int = int(end_date[0]+end_date[1]+end_date[2]+end_date[3])
            end_month_as_int = int(end_date[5]+end_date[6])
            end_day_as_int = int(end_date[8]+end_date[9])

            period_years = end_year_as_int-start_year_as_int
            period_months = end_month_as_int-start_month_as_int
            period_days = end_day_as_int-start_day_as_int

            months_list_1 = ['04','06','09','11']
            months_list_2 = ['01','03','05','07','08','10','12']

            if period_days < 0:
                if str(end_month_as_int) == '02':
                    if end_year_as_int%4 == 0:
                        period_days = 29+period_days
                    if end_year_as_int%4 != 0:
                        period_days = 28+period_days
                for index in range(0,4):
                    if end_month_as_int == int(months_list_1[index]):
                        period_days = 30+period_days
                for index in range(0,7):
                    if end_month_as_int == int(months_list_2    [index]):
                        period_days = 31+period_days
                period_months = period_months-1
            if period_months < 0:
                period_months = 12+period_months
                period_years = period_years-1

            self.period_years = period_years
            self.period_months = period_months
            self.period_days = period_days

  • design our fields view as below , which will show the fields as in the image

                              <group colspan="4" col="4">
                                    <field name="start_date"/>
                                    <field name="end_date"/>
                                    <table>
                                        <tr>
                                            <td>
                                                <b style="font-size:13px;">
                                                    Period&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;
                                                </b>
                                            </td>
                                            <td><field name="period_years" nolabel="1"/></td>
                                            <td>&#160;Y&#160;&#160;-&#160;&#160;</td>
                                            <td><field name="period_months" nolabel="1"/></td>
                                            <td>&#160;M&#160;&#160;-&#160;&#160;</td>
                                            <td><field name="period_days" nolabel="1"/></td>
                                            <td>&#160;D</td>
                                        </tr>
                                    </table>
                                </group>

Tuesday, October 1, 2019

Action buttons in odoo


ODOO


in odoo there are more than one type of button and action button is one of them , so what is an action button ?
An action button is button which be create to call another view , and we can create it by following the steps bellow 
  • create the button in xml file as 
<button name="module_name.view_button_action" icon="fa-check" type="action" string="Graduated Students" />
  • create view_graduated_students function as 
@api.multi
def view_button_action(self):
     return {
            'name': _('ModelName'),
            'view_type': 'form',
            'view_mode': 'tree,form',
            'res_model': 'model.model',
            'view_id': False,
            'type': 'ir.actions.act_window',
            'domain': [],
        }

cost amount by words in odoo

ODOO


 

python def

 

here we have cost amount money as number and we want to generate cost amount as words by using the number cost amount , and we can do it as bellow 
  • create the cost amount number field 
amount = fields.Float(string="Amount", required=True)
  • create the cost amount words field 
amount_words = fields.Float(string="Amount In Writting", readonly=True, compute='_onchange_amount') 

  • create get_amount_in_words function which will convert amount to words and store it in amount_words filed
@api.onchange('amount')
    def
_onchange_amount(self):
        context = self._context or {}
        if hasattr(super(ClassName, self), '_onchange_amount'):
            super(ClassName, self)._onchange_amount()
        if context.get('lang') == 'ar_SY':
            units_name = self.currency_id.currency_unit_label
            cents_name = self.currency_id.currency_subunit_label
            self.amount_words = amount_to_text_ar.amount_to_text(
                self.amount, 'ar', units_name, cents_name)

current date in odoo report

odoo

we can show the current date in odoo -V11- by multi format as bellow 

<span t-esc="context_timestamp(datetime.datetime.now()).strftime('%d/%m/%Y')"/> 
 
<span t-esc="context_timestamp(datetime.datetime.now()).strftime('%Y-%m-%d')"/> 
 
<span t-esc="context_timestamp(datetime.datetime.now()).strftime(''%Y-%m-%d %H:%M'')"/> 

Tuesday, September 3, 2019

checkbox background color in odoo

ODOO

we can go to the css file and write the code below

div.o_checkbox > input:checked + span {
    background-color: #000000;
}

change date background color in odoo


 
we have to go to the css file and write the code bellow to change the defualt color with #33cc33 color

.datepicker .table-condensed > thead {
    color: white;
    /*background-color: #106bac;*/
    /*background-color:#bfb9b9;*/
    /*background-color:#d11f22;*/
    background-color:#33cc33;
}

.datepicker .table-condensed > tbody > tr , .datepicker .table-condensed > tbody > tr > td {
    /*color: white;
    background-color: #1fa135;*/
    background-color:white;
    border-color: white;
    /*border-style: solid;*/
}


.datepicker .table-condensed > thead > tr:first-child th:hover {
    color: white;
    /*background-color: #71b5e5;*/
    /*background-color: #ccc;*/
    /*background-color: #d11f22;*/
    background-color: #33cc33;
}

.datepicker {
    .table-condensed {
        > tbody {
            > tr {
                > td {
                    &.active, .active {
                        background-color: #33cc33;
                        border-radius: 40%;
                    }
                }
            }
        }
    }
}

navbar background color in odoo

ODOO


 

 

to do that we must go to our theme , and open css file and write the code bellow 

.navbar-default {
  background-color: #1fa135;
 
  }

Odoo Invoice Qr code issues

There are two main issues must of us facing with the QR code in Odoo invoice & these issues are 1/ QR code displayed as broken image w...