Skip to Content
Odoo Menu
  • Zaloguj się
  • Wypróbuj za darmo
  • Aplikacje
    Finanse
    • Księgowość
    • Fakturowanie
    • Wydatki
    • Arkusz kalkulacyjny (BI)
    • Dokumenty
    • Podpisy
    Sprzedaż
    • CRM
    • Sprzedaż
    • PoS Sklep
    • PoS Restauracja
    • Subskrypcje
    • Wypożyczalnia
    Strony Internetowe
    • Kreator Stron Internetowych
    • eCommerce
    • Blog
    • Forum
    • Czat na Żywo
    • eLearning
    Łańcuch dostaw
    • Magazyn
    • Produkcja
    • PLM
    • Zakupy
    • Konserwacja
    • Jakość
    Zasoby Ludzkie
    • Pracownicy
    • Rekrutacja
    • Urlopy
    • Ocena pracy
    • Polecenia Pracownicze
    • Flota
    Marketing
    • Marketing Społecznościowy
    • E-mail Marketing
    • SMS Marketing
    • Wydarzenia
    • Automatyzacja Marketingu
    • Ankiety
    Usługi
    • Projekt
    • Ewidencja czasu pracy
    • Usługi Terenowe
    • Helpdesk
    • Planowanie
    • Spotkania
    Produktywność
    • Dyskusje
    • Zatwierdzenia
    • IoT
    • VoIP
    • Baza wiedzy
    • WhatsApp
    Aplikacje trzecich stron Studio Odoo Odoo Cloud Platform
  • Branże
    Sprzedaż detaliczna
    • Księgarnia
    • Sklep odzieżowy
    • Sklep meblowy
    • Sklep spożywczy
    • Sklep z narzędziami
    • Sklep z zabawkami
    Żywienie i hotelarstwo
    • Bar i Pub
    • Restauracja
    • Fast Food
    • Pensjonat
    • Dystrybutor napojów
    • Hotel
    Agencja nieruchomości
    • Agencja nieruchomości
    • Biuro architektoniczne
    • Budowa
    • Zarządzanie nieruchomościami
    • Ogrodnictwo
    • Stowarzyszenie właścicieli nieruchomości
    Doradztwo
    • Biuro księgowe
    • Partner Odoo
    • Agencja marketingowa
    • Kancelaria prawna
    • Agencja rekrutacyjna
    • Audyt i certyfikacja
    Produkcja
    • Tekstylia
    • Metal
    • Meble
    • Jedzenie
    • Browar
    • Prezenty firmowe
    Zdrowie & Fitness
    • Klub sportowy
    • Salon optyczny
    • Centrum fitness
    • Praktycy Wellness
    • Apteka
    • Salon fryzjerski
    Transakcje
    • Złota rączka
    • Wsparcie Sprzętu IT
    • Systemy energii słonecznej
    • Szewc
    • Firma sprzątająca
    • Usługi HVAC
    Inne
    • Organizacja non-profit
    • Agencja Środowiskowa
    • Wynajem billboardów
    • Fotografia
    • Leasing rowerów
    • Sprzedawca oprogramowania
    Przeglądaj wszystkie branże
  • Community
    Ucz się
    • Samouczki
    • Dokumentacja
    • Certyfikacje
    • Szkolenie
    • Blog
    • Podcast
    Pomóż w nauce innym
    • Program Edukacyjny
    • Scale Up! Gra biznesowa
    • Odwiedź Odoo
    Skorzystaj z oprogramowania
    • Pobierz
    • Porównaj edycje
    • Wydania
    Współpracuj
    • Github
    • Forum
    • Wydarzenia
    • Tłumaczenia
    • Zostań partnerem
    • Usługi dla partnerów
    • Zarejestruj swoją firmę rachunkową
    Skorzystaj z usług
    • Znajdź partnera
    • Znajdź księgowego
    • Spotkaj się z doradcą
    • Usługi wdrożenia
    • Opinie klientów
    • Wsparcie
    • Aktualizacje
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Zaplanuj demo
  • Cennik
  • Pomoc

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Księgowość
  • Zapasy
  • PoS
  • Projekt
  • MRP
All apps
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
Wszystkie posty Osoby Odznaki
Tagi (Zobacz wszystko)
odoo accounting v14 pos v15
O tym forum
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
Wszystkie posty Osoby Odznaki
Tagi (Zobacz wszystko)
odoo accounting v14 pos v15
O tym forum
Pomoc

Can not replicate one2many field of one model to other model.

Zaprenumeruj

Otrzymaj powiadomienie o aktywności w tym poście

To pytanie dostało ostrzeżenie
one2manycreate
2 Odpowiedzi
4836 Widoki
Awatar
admin@marutinandanconstruction.in

Hi, 

I am developing an app for testing purpose. In this app I need to copy records saved in one model (includes One2many field aswell) to other model by clicking a button that calls the function which is programmed to the stated task. (Same as Quotation ===> Invoice in sales module)

Here is my model

ORIGIN MODEL (Source, Records will be entered via this model)

from odoo import models, fields, api
from datetime import datetime

class cms_project(models.Model):
_name = 'cms.project'
_description = 'Projects'
_order = 'name asc' # asc or desc

name = fields.Char(string="Project ID", required=True, readonly=True, copy=False, index=True, default='New')
project_short = fields.Char(string="Short Name of Project", required=True)
project_desc = fields.Text(string="Full Name of Work", required=True)
client = fields.Many2one('cms.client', 'Client') # Get Client List from cms.client model
project_ecv = fields.Monetary(compute='_compute_ecv', string="Estimated Cost of Project", readonly=True, store=True)
rebate = fields.Float(string="Percentage (+/-)", required=True)
quoted_total = fields.Monetary(string='Quoted Cost Value of the Work', store=True, readonly=True,
compute='_quoted_total')

work_order_number = fields.Char(string="Client Work Order No.")
work_order_date = fields.Date(string='Work Order Date', required=True, index=True, default=datetime.today())
completion_date = fields.Date(string='Estimated Completition Date', required=True, index=True,
default=datetime.today())

completion_time = fields.Integer(compute='_compute_completion_time', string="Completion time (in Days)",
required=True, index=True, store=False)
remaining_completition_days = fields.Integer(compute='_compute_remaining_completition_days',
string="Remaining Completion Time (in Days)")
currency_id = fields.Many2one(related='boq_line.currency_id', depends=['boq_line.currency_id'], store=True,
string='Currency')
boq_line = fields.One2many('cms.boq.lines', 'boq_id', string='BOQ Lines', copy=True, auto_join=True)
note = fields.Text(string="Notes on BOQ")

@api.model
def create(self, vals):
if vals.get('name', 'New') == 'New':
vals['name'] = self.env['ir.sequence'].next_by_code(
'project.id.seq') or 'New'
return super(cms_project, self).create(vals) # Use return command directly without any "RESULT"

_sql_constraints = [
('pr_short_uniq',
'UNIQUE (project_short)',
'Short name already exists.'),
('pr_id_uniq',
'UNIQUE (name)',
'ID already exists.')]

def _compute_completion_time(self):
for record in self:
record.completion_time = (record.completion_date - record.work_order_date).days

def _compute_remaining_completition_days(self):
for record in self:
record.remaining_completition_days = (record.completion_date - fields.Date.today()).days

@api.depends('boq_line.amount')
def _compute_ecv(self):
global order, ecv_total
for order in self:
ecv_total = 0.0
for line in order.boq_line:
ecv_total += line.amount
order.update({'project_ecv': ecv_total})

@api.depends('project_ecv', 'rebate')
def _quoted_total(self):
for order in self:
calculated = order.project_ecv + (order.project_ecv * (order.rebate / 100))
order.update({
'quoted_total': calculated,
})

@api.model
def create_mb(self,cr):

mb_val_list = []
for order in self:
# prepare MB environment
mb_vals = order._prepare_mb()
# prepare MB lines
for line in order.boq_line:
#self.env['mb.entry.line'].create(line._prepare_mb_line())
mb_vals['mb_line'].append((0, 0, line._prepare_mb_line()))
mb_val_list.append(mb_vals)
moves = self.env['mb.entry'].create(mb_val_list)
return moves

@api.model
def _prepare_mb(self):
self.ensure_one()
mb_vals = {
'mb_no': self.name,
'project_short': self.project_short,
'project_desc': self.project_desc,
'project_ecv': self.project_desc,
'client': self.client,
'rebate': self.rebate,
'quoted_total': self.quoted_total,
'work_order_number': self.work_order_number,
'work_order_date': self.work_order_date,
'completion_date': self.completion_date,
'completion_time': self.completion_time,
'remaining_completition_days': self.remaining_completition_days,
'currency_id': self.currency_id,
'mb_line': [],
}
return mb_vals

class cms_boq_lines(models.Model):
_name = 'cms.boq.lines'
_description = "BOQ Lines"
_rec_name = 'item_id'
# name = fields.Char(string="BOQ Lines")
boq_id = fields.Many2one('cms.project', string='BOQ ID', copy=True, required=True, ondelete='cascade', index=True)

item_id = fields.Char(string="SNo.", store=True)
item_short = fields.Many2one('product.product', string='Item', store=True)
item_des = fields.Text(string='Item Description', store=True)
item_qty = fields.Float(string="Estimated QTY.", required=True, digits=(30, 3), store=True)
item_rate = fields.Monetary(string="SOR Rate", required=True, store=True, )
uom = fields.Many2one('uom.uom', string='Per', store=True)
amount = fields.Monetary(compute='_amount', readonly=True, string="Amount", required=True, strore=True)
currency_id = fields.Many2one('res.currency', string='Currency')

@api.depends('item_qty', 'item_rate')
def _amount(self):
for line in self:
qty = line.item_qty
rate = line.item_rate
line.amount = qty * rate

def _prepare_mb_line(self):
self.ensure_one()
res = {
'boq_id': self.boq_id,
'mb_id':self.boq_id,
'item_id': self.item_id,
'item_short': self.item_short,
'item_qty': self.item_qty,
'item_des': self.item_des,
'item_rate': self.item_rate,
'uom': self.uom,
'amount': self.amount,
}
return res    

 

Destination MODEL ( Records will be replicated in this model)


from odoo import models, fields, api
from datetime import datetime

class mb_entry(models.Model):
_name = 'mb.entry'
_description = "Measurement Book"
_rec_name = 'mb_no'
mb_no = fields.Char(string="MB SNo.")

execution_date = fields.Date(string='Execution Date', required=True, index=True, default=datetime.today())
entry_date = fields.Date(string='Entry Date', required=True, index=True, default=datetime.today(), readonly=True)

project = fields.Char(string='Project')
project_short = fields.Char(string="Short Name of Project", required=True)
project_desc = fields.Text(string="Full Name of Work", required=True)

client = fields.Char(string="Client")
project_ecv = fields.Char(string="Estimated Cost of Project", readonly=True, store=True)
rebate = fields.Char(string="Percentage (+/-)", required=True)
quoted_total = fields.Char(string='Quoted Cost Value of the Work', store=True, readonly=True)

work_order_number = fields.Char(string="Client Work Order No.", copy=False)
work_order_date = fields.Date(string='Work Order Date', required=True, index=True)
completion_date = fields.Date(string='Estimated Completition Date', required=True, index=True)

completion_time = fields.Integer(string="Completion time (in Days)",
required=True, index=True, store=False)
remaining_completition_days = fields.Integer(string="Remaining Completion Time (in Days)")
currency_id = fields.Many2one(related='mb_line.currency_id', depends=['mb_line.currency_id'], store=True,
string='Currency')
mb_line = fields.One2many('mb.entry.line', 'mb_id', string='Measurement Book', copy=True, auto_join=True, readonly=True)




@api.onchange('project')
def project_onchange(self):
for rec in self:
if rec.project:
rec.project_short = rec.project.project_short
rec.project_desc = rec.project.project_desc


# def default_get(self):
class mb_entry_line(models.Model):
_name = 'mb.entry.line'
_description = "Measurement Book Lines"
_rec_name = 'mb_id'
mb_id = fields.Many2one('mb.entry',string='MB Lines ID', index=True,
copy=False)

item_id = fields.Char(string="SNo.", store=True, readonly=True)
item_short = fields.Char(string='Item', store=True, readonly=True)
item_qty = fields.Float(string="Estimated QTY.", required=True, digits=(30, 3), store=True, readonly=True)
boq_id = fields.Char(string='BOQ ID')
item_des = fields.Text(string='Item Description', store=True)
item_rate = fields.Monetary(string="SOR Rate", required=True, store=True,)
uom = fields.Char(string='Per', store=True)
amount = fields.Monetary(readonly=True, string="Amount", required=True, strore=True)
currency_id = fields.Many2one('res.currency', string='Currency')

0
Awatar
Odrzuć
admin@marutinandanconstruction.in
Autor

FOCUS METHOD

@api.model

def create_mb(self,cr):

mb_val_list = []

for order in self:

# prepare MB environment

mb_vals = order._prepare_mb()

# prepare MB lines

for line in order.boq_line:

#self.env['mb.entry.line'].create(line._prepare_mb_line())

mb_vals['mb_line'].append((0, 0, line._prepare_mb_line()))

mb_val_list.append(mb_vals)

moves = self.env['mb.entry'].create(mb_val_list)

return moves

@api.model

def _prepare_mb(self):

self.ensure_one()

mb_vals = {

'mb_no': self.name,

'project_short': self.project_short,

'project_desc': self.project_desc,

'project_ecv': self.project_desc,

'client': self.client,

'rebate': self.rebate,

'quoted_total': self.quoted_total,

'work_order_number': self.work_order_number,

'work_order_date': self.work_order_date,

'completion_date': self.completion_date,

'completion_time': self.completion_time,

'remaining_completition_days': self.remaining_completition_days,

'currency_id': self.currency_id,

'mb_line': [],

}

return mb_vals

Awatar
admin@marutinandanconstruction.in
Autor Najlepsza odpowiedź

Isuue was with 

@api.model

After romoving, the code worked!!!

0
Awatar
Odrzuć
Podoba Ci się ta dyskusja? Dołącz do niej!

Stwórz konto dzisiaj, aby cieszyć się ekskluzywnymi funkcjami i wchodzić w interakcje z naszą wspaniałą społecznością!

Zarejestruj się
Powiązane posty Odpowiedzi Widoki Czynność
[8.0] Error saving one2many when edit before save.
one2many create
Awatar
Awatar
1
lis 17
5093
Best way to create one2many records in backend
one2many create update
Awatar
0
lis 22
4904
How can I get data from the rows being created in a list view before saving? Rozwiązane
one2many create access
Awatar
Awatar
2
wrz 21
17726
one2many update() vs self.env[]
one2many create api
Awatar
0
lip 21
4498
Failing to write Many2one field Rozwiązane
one2many create relationfield
Awatar
Awatar
1
lut 19
4477
Społeczność
  • Samouczki
  • Dokumentacja
  • Forum
Open Source
  • Pobierz
  • Github
  • Runbot
  • Tłumaczenia
Usługi
  • Hosting Odoo.sh
  • Wsparcie
  • Aktualizacja
  • Indywidualne rozwiązania
  • Edukacja
  • Znajdź księgowego
  • Znajdź partnera
  • Zostań partnerem
O nas
  • Nasza firma
  • Zasoby marki
  • Skontaktuj się z nami
  • Oferty pracy
  • Wydarzenia
  • Podcast
  • Blog
  • Klienci
  • Informacje prawne • Prywatność
  • Bezpieczeństwo Odoo
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo to pakiet aplikacji biznesowych typu open source, które zaspokoją wszystkie potrzeby Twojej firmy: CRM, eCommerce, księgowość, inwentaryzacja, punkt sprzedaży, zarządzanie projektami itp.

Unikalną wartością Odoo jest to, że jest jednocześnie bardzo łatwe w użyciu i w pełni zintegrowane.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now