У меня проблема с сохранением данных в odoo 11.0, пользовательский модуль - PullRequest
0 голосов
/ 25 ноября 2018

Я пытаюсь добавить дополнительные поля в модели (stock.picking, stock_move, stock.move.line)

Код работает нормально, но не сохраняет данные в базу данных

введите описание изображения здесь

введите описание изображения здесь

код IS:

from odoo import models,fields, api

от odoo.addonsимпортировать decimal_precision как dp из num2words импортировать num2words

класс StockMove (models.Model): _inherit = "stock.move"

br_currency_id = fields.Many2one(related='picking_id.currency_id',
                                 store=True,
                                 string='Currency',
                                 readonly=True)
br_price_unit = fields.Float(string='U. Price',
                             required=True,
                             digits=dp.get_precision('Product Price'),
                             store=True)
br_price_total = fields.Float(string='Total', store=True)

"" "@ api.onchange ('product_id','br_price_unit', 'amount_done') def _compute_amount (self): self.br_price_unit = self.product_id.standard_price self.br_price_total = self.product_id.standard_price * self.quantity_done ""

* 1022Модель): _inherit = "stock.move.line"
br_currency_id = fields.Many2one(related='picking_id.currency_id',
                                 store=True, string='Currency', readonly=True)
br_price_unit = fields.Float(string='U. Price',
                             required=True,
                             digits=dp.get_precision('Product Price'),
                             store=True)
br_price_total = fields.Float(string='Total', store=True)

@api.onchange('product_id', 'br_price_unit', 'qty_done')
def _compute_amount(self):
    self.br_price_unit = self.product_id.standard_price
    self.br_price_total = self.product_id.standard_price * self.qty_done

Класс StockPicking (models.Model): _inherit = "stock.picking"

br_vendor_ref = fields.Char(string="Vendor Reference")
currency_id = fields.Many2one('res.currency', 'Currency',
                                 readonly=True,
                                 default=lambda self: self.env.user.company_id.currency_id.id)
br_amount_total = fields.Monetary(string='Total',
                                  store=True,
                                  readonly=True,
                                  compute='_amount_all')
br_total_amount_in_words = fields.Char(string="Amount in Words",
                                    store=True,
                                    compute='_amount_all')

"""
def _amount_all(self):
    for p in self:
        p.amount_total=0.0
        p.total_amount_in_words='a'
"""
@api.depends('move_line_ids.br_price_total')
def _amount_all(self):
    for picking in self:
        amount_total = 0.0
        for line in picking.move_line_ids:
            amount_total += line.br_price_total

        lang = picking.partner_id and picking.partner_id.lang[:2]
        try:
            test = num2words(42, lang=lang)
        except NotImplementedError:
            lang = 'en'
        numword = num2words(amount_total, lang=lang)

        picking.update({
            'br_amount_total': amount_total,
            'br_total_amount_in_words': numword,
        })
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...