Python / Odoo Developer

Welcome!

This community is for professionals and enthusiasts of our products and services. Share and discuss the best content and new marketing ideas, build your professional profile and become a better marketer together.

0

Locale Linux

Avatar
Administrator

To Add new locales in the server type

dpkg-reconfigure locales

With the spacebar add locales and Enter to confirm.


    def get_last_revenues_vendor(self):
vendor_partner = self.env.user.partner_id
today = datetime.date.today()
out = []
try:
locale.setlocale(locale.LC_ALL, self.env.user.lang) # Set user locale language
except Exception as ex:
logging.error('Cannot set locale for %r please install it in the server, error %r' % (self.env.user.lang, ex))
import calendar
for month_count in [-3, -2, -1]:
month_date = today + relativedelta(months=month_count) # Go back of number of months
days = monthrange(month_date.year, month_date.month) # Get days in given month
_, number_of_days = days
start_date = datetime.date(month_date.year, month_date.month, 1)
end_date = datetime.date(month_date.year, month_date.month, number_of_days)
purchase_line_ids = self.env['purchase.order.line'].search([
('create_date', '>', start_date),
('create_date', '<', end_date),
])
amount = 0
for purchase_line_id in purchase_line_ids:
if purchase_line_id.order_id.partner_id.id == vendor_partner.id:
amount += purchase_line_id.price_subtotal
# Compute month name using locale and calendar
out.append('Mese %s %s €' % (calendar.month_name[start_date.month].capitalize(), amount))
return out


Avatar
Discard